Esempio n. 1
0
        public override void AfterApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.AfterApplyChanges(dbHelper, entity);

            if (entity.ChangeStatus.IsIn(EntityChangeTypes.Add, EntityChangeTypes.Modify))
            {
                if (entity.GetFieldValue <Guid>("OpType") == OptionSetHelper.GetOptionSetItemID("wm.MontageOrDemontage", "Montage"))
                {
                    //حواله مونتاژ
                    CreateGhabzOrHavale(entity, "HavaleAmaliateMontage");

                    //رسید مونتاژ
                    CreateGhabzOrHavale(entity, "ResideAmaliateMontage");
                }
                else if (entity.GetFieldValue <Guid>("OpType") == OptionSetHelper.GetOptionSetItemID("wm.MontageOrDemontage", "Demontage"))
                {
                    //حواله دمونتاژ
                    CreateGhabzOrHavale(entity, "HavaleAmaliateDemontage");

                    //رسید دمونتاژ
                    CreateGhabzOrHavale(entity, "ResideAmaliateDemontage");
                }
            }

            if (entity.ChangeStatus != EntityChangeTypes.Delete)
            {
                if (entity.FieldExists("StuffComponents") && entity.GetFieldValue <EntityList>("StuffComponents") != null)
                {
                    dbHelper.ApplyChanges(entity.GetFieldValue <EntityList>("StuffComponents"));
                }
            }
        }
Esempio n. 2
0
        public Entity GetUserWarningItemsCount()
        {
            var resultEntity = new Entity();

            var core         = CoreComponent.Instance;
            var dbHelper     = core.MainDbHelper;
            var openStatusID = OptionSetHelper.GetOptionSetItemID("crm.SalesCaseStatuses", "Open");

            var tedadeParvandeHayeRakedeMan = dbHelper.GetCount("crm_SalesCasesView",
                                                                string.Format("Status = '{0}' and IsActive = 1 and IsStagnant = 1 and OwnerUser = '******'",
                                                                              openStatusID, core.GetCurrentSessionUserID()));

            resultEntity.AddField("TedadeParvandehayeRakedeMan", tedadeParvandeHayeRakedeMan);

            var tedadeKolleParvandeHayeRaked = dbHelper.GetCount("crm_SalesCasesView",
                                                                 string.Format("Status = '{0}' and IsActive = 1 and IsStagnant = 1",
                                                                               openStatusID));

            resultEntity.AddField("TedadeParvandehayeRakedeHame", tedadeKolleParvandeHayeRaked);

            var tedadeParvandeHayeMoavagheMan = dbHelper.GetCount("crm_SalesCasesView",
                                                                  string.Format("Status = '{0}' and IsActive = 1 and DaysRemainedInCurrentStage > CurrentStageAllowedDays and OwnerUser = '******'",
                                                                                openStatusID, core.GetCurrentSessionUserID()));

            resultEntity.AddField("TedadeParvandehayeMoavagheMan", tedadeParvandeHayeMoavagheMan);

            var tedadeKolleParvandeHayeMoavagh = dbHelper.GetCount("crm_SalesCasesView",
                                                                   string.Format("Status = '{0}' and IsActive = 1 and DaysRemainedInCurrentStage > CurrentStageAllowedDays",
                                                                                 openStatusID));

            resultEntity.AddField("TedadeParvandehayeMoavagheHame", tedadeKolleParvandeHayeMoavagh);

            return(resultEntity);
        }
Esempio n. 3
0
        //آپدیت حساب آیتم های سندی ک برای این حساب ها سطح جدید در درخت کدینگ حساب، اضافه شده است
        //حساب آیتم های سند به حسابی که در سطح جدید اضافه شده است آپدیت می شود
        private void UpdateAccDocItemsAccountToNewAccountOfParentAccount(Entity entity)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            var parentAccountID = entity.GetFieldValue <Guid?>("ParentAccount");

            if (parentAccountID != null)
            {
                var AccountLevelKolID  = OptionSetHelper.GetOptionSetItemID("acc.AccountLevel", "Kol");
                var AccountLevelMoinID = OptionSetHelper.GetOptionSetItemID("acc.AccountLevel", "Moin");

                var parentAccountIsKolOrMoin = dbHelper.EntityExists("acc.account",
                                                                     string.Format("ID = '{0}' and AccountLevel in ('{1}', '{2}')", parentAccountID, AccountLevelKolID, AccountLevelMoinID));

                if (parentAccountIsKolOrMoin)
                {
                    var accDocItems = dbHelper.FetchMultiple("acc.accDocItem",
                                                             string.Format("Account = '{0}'", parentAccountID),
                                                             null, null, null, null).Entities;

                    foreach (var accDocItem in accDocItems)
                    {
                        accDocItem.ChangeStatus = "Modify";
                        accDocItem.SetFieldValue("Account", entity.GetFieldValue <Guid>("ID"));
                        dbHelper.UpdateEntity(accDocItem);
                    }
                }
            }
        }
Esempio n. 4
0
        public void SavePhoneNumberForPerson(string callID, string callNumber, string PersonID)
        {
            //DebugHelper.Break();
            using (var dbHelper = DbHelperFactory.CreateMainDbEntityDbHelper())
            {
                using (var tranManager = new DbTransactionManager(dbHelper))
                {
                    if (PersonID != null)
                    {
                        var phoneNumberEntity = dbHelper.CreateNewEntity("cmn.PhoneNumber");
                        var telTypeID         = OptionSetHelper.GetOptionSetItemID("cmn.PhoneType", "Unknown");

                        phoneNumberEntity.SetFieldValue("Person", PersonID);
                        phoneNumberEntity.SetFieldValue("Phone", callNumber);
                        phoneNumberEntity.SetFieldValue("Note", "تماس دریافتی");
                        phoneNumberEntity.SetFieldValue("TelType", telTypeID);

                        dbHelper.ApplyChanges(phoneNumberEntity);
                    }

                    var receivedCallEntity = dbHelper.FetchSingle("cmn.ReceivedCall", string.Format("ID = '{0}'", callID), null);
                    receivedCallEntity.SetFieldValue("CallPerson", PersonID);
                    receivedCallEntity.ChangeStatus = "Modify";

                    dbHelper.ApplyChanges(receivedCallEntity);

                    tranManager.Commit();
                }
            }
        }
Esempio n. 5
0
        public string DeleteWarehouseAccDoc(DateTime fromDate, Guid financialYearID)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;
            var message  = "اسناد انبار به شماره های ";

            var vazeyatRialiShodeID      = OptionSetHelper.GetOptionSetItemID("wm.VaziyatRialiAsnadAnbar", "RialiShode");
            var vazeyatRialiSanadShodeID = OptionSetHelper.GetOptionSetItemID("wm.VaziyatRialiAsnadAnbar", "SanadShode");
            var accDocEntities           = dbHelper.FetchMultipleBySqlQuery(string.Format(@"
                select  AccDoc , AccDoc.DocNo
                from wm_GhabzOrHavaleha GhabzOrHavale
	               left join acc_AccDocs AccDoc on AccDoc.ID = GhabzOrHavale.AccDoc
                where GhabzOrHavale.AccDoc is not null and
	               GhabzOrHavale.IssueDate >= '{0}'
                group by AccDoc , DocNo", fromDate)).Entities;

            for (int i = 0; i < accDocEntities.Count; i++)
            {
                dbHelper.AdoDbHelper.ExecuteNonQuery(string.Format(@"
                    update wm_GhabzOrHavaleha
                    set AccDoc = null,
	                    VazeyatRialiShodan = '{0}'
                    where AccDoc = '{1}'", vazeyatRialiShodeID, accDocEntities[i].GetFieldValue <Guid>("AccDoc")), null);

                message += accDocEntities[i].GetFieldValue <int>("DocNo") + (i + 1 == accDocEntities.Count ? " " : ", ");
                dbHelper.DeleteEntity(dbHelper.FetchSingleByID("acc.AccDoc", accDocEntities[i].GetFieldValue <Guid>("AccDoc"), null));
            }

            return(message + "حذف شدند.\r\n");
        }
Esempio n. 6
0
        public string GenerateWarehouseAccDoc(DateTime toDate, Guid financialYearID)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            var vazeyatRialiShodeID = OptionSetHelper.GetOptionSetItemID("wm.VaziyatRialiAsnadAnbar", "RialiShode");

            var forAccDocsInfosEntities = dbHelper.FetchMultipleBySqlQuery(string.Format(@"
                select  IssueDate , OrganizationUnit , FinancialDocType 
                from wm_GhabzOrHavaleha
                where FinancialYear = '{0}' and IssueDate <= '{2}' and
                    VazeyatRialiShodan = '{1}'
                group by IssueDate, OrganizationUnit, FinancialDocType 
                order by IssueDate", financialYearID, vazeyatRialiShodeID, toDate)).Entities;

            if (forAccDocsInfosEntities.Count == 0)
            {
                throw new AfwException("رسید/ حواله ریالی شده قبل از تاریخ {0} یافت نشد", DateTimeHelper.GregorianDateTimeToPersian(toDate).Split(' ')[0]);
            }

            string message = "اسناد حسابداری با شماره های ";

            for (int i = 0; i < forAccDocsInfosEntities.Count; i++)
            {
                Int64 maxDocNo = 0;
                CheckWarehouseDocsHasAccount(financialYearID,
                                             forAccDocsInfosEntities[i].GetFieldValue <Guid>("FinancialDocType"),
                                             forAccDocsInfosEntities[i].GetFieldValue <Guid>("OrganizationUnit"),
                                             toDate);

                using (var tranManager = new DbTransactionManager(dbHelper))
                {
                    try
                    {
                        Guid?accDocID = null;
                        acc.Instance.InsertAccDocMaster(ref accDocID, "WarehouseDoc", forAccDocsInfosEntities[i].GetFieldValue <DateTime>("IssueDate"), financialYearID,
                                                        forAccDocsInfosEntities[i].GetFieldValue <Guid>("FinancialDocType"),
                                                        forAccDocsInfosEntities[i].GetFieldValue <Guid>("OrganizationUnit"),
                                                        "سند انبار", true);

                        CreateWarehouseAccDocItems((Guid)accDocID,
                                                   forAccDocsInfosEntities[i].GetFieldValue <Guid>("FinancialDocType"),
                                                   forAccDocsInfosEntities[i].GetFieldValue <Guid>("OrganizationUnit"),
                                                   financialYearID, forAccDocsInfosEntities[i].GetFieldValue <DateTime>("IssueDate"));

                        maxDocNo = dbHelper.FetchSingle("acc.AccDoc", string.Format("ID = '{0}'", accDocID), null).GetFieldValue <Int64>("DocNo");
                        message += maxDocNo + (i + 1 == forAccDocsInfosEntities.Count ? " " : " ,");

                        tranManager.Commit();
                    }
                    catch (Exception ex)
                    {
                        throw new AfwException("خطا در صدور سند حسابداری.\r\n" + ex.Message);
                    }
                }
            }

            return(message + " صادر شدند.\r\n");
        }
Esempio n. 7
0
        public void SevePersonGroupAccounts(Guid accountID, Guid personGroupID, Guid financialYearID)
        {
            //DebugHelper.Break();  
            using (var dbHelper = DbHelperFactory.CreateMainDbEntityDbHelper())
            {
                var kolLevelID = OptionSetHelper.GetOptionSetItemID("acc.AccountLevel", "Kol");
                var moinLevelID = OptionSetHelper.GetOptionSetItemID("acc.AccountLevel", "Moin");
                var tafsiliLevelID = OptionSetHelper.GetOptionSetItemID("acc.AccountLevel", "Tafsili");
                 
                var accountEntity = dbHelper.FetchSingle("acc.Account", string.Format("ID = '{0}'", accountID), null);

                if (accountEntity.GetFieldValue<Guid>("AccountLevel") == kolLevelID)
                {
                    var moinAccounts = dbHelper.FetchMultiple("acc.Account",
                        string.Format("ParentAccount = '{0}' and AccountLevel = '{1}'", accountID, moinLevelID), null, null, null, null);
                    if (moinAccounts.Entities.Count > 0)
                    {
                        for (var i = 0; i < moinAccounts.Entities.Count; i++)
                        {
                            var moinAccountID = moinAccounts.Entities[i].GetFieldValue<Guid>("ID");
                            var tafsiliAccounts = dbHelper.FetchMultiple("acc.Account",
                                string.Format("ParentAccount = '{0}' and AccountLevel = '{1}'", moinAccountID, tafsiliLevelID), null, null, null, null);
                            if (tafsiliAccounts.Entities.Count > 0)
                            {
                                for (var j = 0; j < tafsiliAccounts.Entities.Count; j++)
                                {
                                    var tafsiliAccountID = tafsiliAccounts.Entities[j].GetFieldValue<Guid>("ID");
                                    SevePersonGroupAccount(tafsiliAccountID, personGroupID, financialYearID);
                                }
                            }
                            else
                                SevePersonGroupAccount(moinAccountID, personGroupID, financialYearID);
                        }
                    }
                    else
                        SevePersonGroupAccount(accountID, personGroupID, financialYearID);
                }
                else if (accountEntity.GetFieldValue<Guid>("AccountLevel") == moinLevelID)
                {
                    var tafsiliAccounts = dbHelper.FetchMultiple("acc.Account",
                           string.Format("ParentAccount = '{0}' and AccountLevel = '{1}'", accountID, tafsiliLevelID), null, null, null, null);
                    if (tafsiliAccounts.Entities.Count > 0)
                    {
                        for (var j = 0; j < tafsiliAccounts.Entities.Count; j++)
                        {
                            var tafsiliAccountID = tafsiliAccounts.Entities[j].GetFieldValue<Guid>("ID");
                            SevePersonGroupAccount(tafsiliAccountID, personGroupID, financialYearID);
                        }
                    }
                    else
                        SevePersonGroupAccount(accountID, personGroupID, financialYearID);
                }
                else
                    SevePersonGroupAccount(accountID, personGroupID, financialYearID);
            }
        }
Esempio n. 8
0
        private bool ValidateAccDocAccounts(Entity entity)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            if (entity.GetFieldValue <decimal>("GeneralDiscount") != 0)
            {
                throw new AfwException("GeneralDiscount has value. not Implemented.");
            }

            var financialGroupID     = entity.GetFieldValue <Guid>("FinancialGroup");
            var financialGroupEntity = dbHelper.FetchSingleByID("cmn.FinancialGroup", financialGroupID, null);

            if (financialGroupEntity == null)
            {
                return(false);
            }

            string docGenerationMethod          = OptionSetHelper.GetOptionSetItemName(financialGroupEntity.GetFieldValue <Guid>("SalesDocGenerationMethod"));
            var    hesabeBargashtAzForoosh      = financialGroupEntity.GetFieldValue <Guid?>("ShabloneSanad_HesabeBargashtAzForoosh");
            var    hesabeBargashtAzForooshAmani = financialGroupEntity.GetFieldValue <Guid?>("ShabloneSanad_HesabeBargashtAzForoosheAmani");
            var    hesabeMoshtarian             = financialGroupEntity.GetFieldValue <Guid?>("ShabloneSanad_HesabeMoshtarian");
            var    hesabeMoshtarianAmani        = financialGroupEntity.GetFieldValue <Guid?>("ShabloneSanad_HesabeMoshtarianAmani");
            var    hesabeAvarezBarArzeshAfzoode = financialGroupEntity.GetFieldValue <Guid?>("ShabloneSanad_HesabeAvarezBarArzeshAfzoode_Foroosh");
            var    hesabeMaliatBarArzeshAfzoode = financialGroupEntity.GetFieldValue <Guid?>("ShabloneSanad_HesabeMaliatBarArzeshAfzoode_Foroosh");
            var    hesabeTakhfifat = financialGroupEntity.GetFieldValue <Guid?>("ShabloneSanad_HesabeTakhfifat_Foroosh");
            var    isAmani         = entity.GetFieldValue <bool>("IsAmani");

            if (isAmani)
            {
                if (hesabeBargashtAzForooshAmani == null || hesabeMoshtarianAmani == null)
                {
                    return(false);
                }
            }
            else
            {
                if ((docGenerationMethod == "TakhfifDarSanadJodaShavad" &&
                     (hesabeBargashtAzForoosh == null ||
                      hesabeMoshtarian == null ||
                      hesabeAvarezBarArzeshAfzoode == null ||
                      hesabeMaliatBarArzeshAfzoode == null ||
                      hesabeTakhfifat == null))
                    ||
                    (docGenerationMethod == "TakhfifDarSanadJodaNashavad" &&
                     (hesabeBargashtAzForoosh == null ||
                      hesabeMoshtarian == null ||
                      hesabeAvarezBarArzeshAfzoode == null ||
                      hesabeMaliatBarArzeshAfzoode == null))
                    )
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 9
0
        public Guid GetFirstLeafOfAccountTree(Guid accountID)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            var kolLevelID     = OptionSetHelper.GetOptionSetItemID("acc.AccountLevel", "Kol");
            var moinLevelID    = OptionSetHelper.GetOptionSetItemID("acc.AccountLevel", "Moin");
            var tafsiliLevelID = OptionSetHelper.GetOptionSetItemID("acc.AccountLevel", "Tafsili");

            var accountEntity = dbHelper.FetchSingle("acc.Account", string.Format("ID = '{0}'", accountID), null);

            if (accountEntity.GetFieldValue <Guid>("AccountLevel") == kolLevelID)
            {
                var moinAccounts = dbHelper.FetchMultiple("acc.Account",
                                                          string.Format("ParentAccount = '{0}' and AccountLevel = '{1}'", accountID, moinLevelID), null, null, null, null);

                if (moinAccounts.Entities.Count == 0)
                {
                    return(accountID);
                }

                var moinAccountID = moinAccounts.Entities[0].GetFieldValue <Guid>("ID");

                for (var i = 0; i < moinAccounts.Entities.Count; i++)
                {
                    moinAccountID = moinAccounts.Entities[i].GetFieldValue <Guid>("ID");
                    var tafsiliAccounts = dbHelper.FetchMultiple("acc.Account",
                                                                 string.Format("ParentAccount = '{0}' and AccountLevel = '{1}'", moinAccountID, tafsiliLevelID), null, null, null, null);

                    if (tafsiliAccounts.Entities.Count > 0)
                    {
                        var tafsiliAccountID = tafsiliAccounts.Entities[0].GetFieldValue <Guid>("ID");
                        return(tafsiliAccountID);
                    }
                }

                return(moinAccountID);
            }
            else if (accountEntity.GetFieldValue <Guid>("AccountLevel") == moinLevelID)
            {
                var tafsiliAccounts = dbHelper.FetchMultiple("acc.Account",
                                                             string.Format("ParentAccount = '{0}' and AccountLevel = '{1}'", accountID, tafsiliLevelID), null, null, null, null);

                if (tafsiliAccounts.Entities.Count == 0)
                {
                    return(accountID);
                }

                var tafsiliAccountID = tafsiliAccounts.Entities[0].GetFieldValue <Guid>("ID");
                return(tafsiliAccountID);
            }
            else
            {
                return(accountID);
            }
        }
Esempio n. 10
0
        private EntityList GetPersonPreviewInfo_PersonPhoneNumberInfos(Entity person)
        {
            var phoneNumbersInfos = new EntityList();

            if (!string.IsNullOrEmpty(person.GetFieldValue <string>("TelNumber1")))
            {
                var phoneNumberInfo = new Entity();
                phoneNumberInfo.AddField("PhoneType", "تلفن ثابت");
                phoneNumberInfo.AddField("PhoneNumber", person.GetFieldValue <string>("TelNumber1"));
                phoneNumberInfo.AddField("Description", null);
                phoneNumbersInfos.Entities.Add(phoneNumberInfo);
            }

            if (!string.IsNullOrEmpty(person.GetFieldValue <string>("WorkPhoneNumber")))
            {
                var phoneNumberInfo = new Entity();
                phoneNumberInfo.AddField("PhoneType", "تلفن محل کار");
                phoneNumberInfo.AddField("PhoneNumber", person.GetFieldValue <string>("WorkPhoneNumber"));
                phoneNumberInfo.AddField("Description", null);
                phoneNumbersInfos.Entities.Add(phoneNumberInfo);
            }

            if (!string.IsNullOrEmpty(person.GetFieldValue <string>("MobilePhoneNumber1")))
            {
                var phoneNumberInfo = new Entity();
                phoneNumberInfo.AddField("PhoneType", "تلفن همراه");
                phoneNumberInfo.AddField("PhoneNumber", person.GetFieldValue <string>("MobilePhoneNumber1"));
                phoneNumberInfo.AddField("Description", null);
                phoneNumbersInfos.Entities.Add(phoneNumberInfo);
            }

            if (!string.IsNullOrEmpty(person.GetFieldValue <string>("Fax")))
            {
                var phoneNumberInfo = new Entity();
                phoneNumberInfo.AddField("PhoneType", "فکس");
                phoneNumberInfo.AddField("PhoneNumber", person.GetFieldValue <string>("Fax"));
                phoneNumberInfo.AddField("Description", null);
                phoneNumbersInfos.Entities.Add(phoneNumberInfo);
            }

            foreach (var phoneNumber in person.GetFieldValue <EntityList>("PhoneNumbers").Entities)
            {
                var phoneNumberInfo = new Entity();
                var phoneType       = OptionSetHelper.GetOptionSetItems("cmn.PhoneType").First(
                    o => o.GetFieldValue <Guid>("ID") == phoneNumber.GetFieldValue <Guid>("TelType")).GetFieldValue <string>("Title");
                phoneNumberInfo.AddField("PhoneType", phoneType);

                phoneNumberInfo.AddField("PhoneNumber", phoneNumber.GetFieldValue <string>("Phone"));
                phoneNumberInfo.AddField("Description", phoneNumber.GetFieldValue <string>("Note"));

                phoneNumbersInfos.Entities.Add(phoneNumberInfo);
            }

            return(phoneNumbersInfos);
        }
Esempio n. 11
0
        //پرونده های معوق: بیش از زمان مجاز مرحله، در مرحله جاری مانده اند
        //پرونده های راکد: از زمان آخرین تغییر پرونده، تعداد روز مشخصی (با توجه به تنظیمات) گذشته است

        public int GetUserTotalWarningItemsCount()
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            var count = dbHelper.GetCount("crm_SalesCasesView",
                                          string.Format(@"Status = '{0}' and IsActive = 1 
                    and (IsStagnant = 1 or DaysRemainedInCurrentStage > CurrentStageAllowedDays)",
                                                        OptionSetHelper.GetOptionSetItemID("crm.SalesCaseStatuses", "Open")));

            return(count);
        }
Esempio n. 12
0
        public override void AfterApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.AfterApplyChanges(dbHelper, entity);

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

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

            if (entity.ChangeStatus == EntityChangeTypes.Delete)
            {
                if (entity.GetFieldValue <Guid>("GhabzOrHavale") != wm.Instance.DeletingGhabzOrHavaleID)
                {
                    wm.Instance.CompareRefDocItemsWithGhabzOrHavaleItems(ghabzOrHavale);
                }
            }
            else
            {
                if (warehouseDocName == "Havale" &&
                    ghabzOrHavaleTypeEntity.GetFieldValue <bool>("Havale_CheckStuffStock"))
                {
                    CheckStuffStock(entity, stuffLocationID,
                                    ghabzOrHavale.GetFieldValue <DateTime>("IssueDate"),
                                    null, null);
                }

                //bool? isValuationActivity = null;
                //if (entity.ChangeStatus == EntityChangeTypes.Modify)
                //{
                //    if (wm.Instance.IsRunningValuation || wm.Instance.IsRunningUnvaluation || wm.Instance.IsEvaluatingDocsForValuation)
                //        isValuationActivity = true;
                //    else
                //    {
                //        var changedFieldNames = cmn.Instance.GetChangedFieldsName(_OldEntity, entity, null);
                //        if (changedFieldNames.Any(o => !o.IsIn("LastModifyTime", "LastModifierUser", "RialiAmount")))
                //            isValuationActivity = true;
                //        else
                //            isValuationActivity = false;
                //    }
                //}
                //else
                //    isValuationActivity = false;

                if (!wm.Instance.InventoryValuationBL.IsInValuationOperation)
                {
                    ApplyItemSerialNumbersChanges(ghabzOrHavale, entity);
                }
            }
        }
Esempio n. 13
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);
                    }
                }
            }
        }
Esempio n. 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;
            }

            if (entity.ChangeStatus.IsIn(EntityChangeTypes.Add, EntityChangeTypes.Modify))
            {
                var ghabzOrHavale           = dbHelper.FetchSingleByID("wm.GhabzOrHavale", entity.GetFieldValue <Guid>("GhabzOrHavale"), null);
                var ghabzOrHavaleTypeEntity = wm.Instance.GetGhabzOrHavaleTypeEntity(ghabzOrHavale.GetFieldValue <Guid>("GhabzOrHavaleType"));
                var warehouseDocName        = OptionSetHelper.GetOptionSetItemName(ghabzOrHavaleTypeEntity.GetFieldValue <Guid>("WarehouseDocType"));
                var stuffLocationID         = ghabzOrHavale.GetFieldValue <Guid?>("StuffLocation");
                var stuffLocation           = dbHelper.FetchSingleByID("cmn.StuffLocation", (Guid)stuffLocationID, null);
                var stuff = dbHelper.FetchSingleByID("cmn.Stuff", entity.GetFieldValue <Guid>("Stuff"), null);

                if (entity.FieldExists("Stuff_Entity"))
                {
                    entity.RemoveField("Stuff_Entity");
                }

                if (entity.GetFieldValue <int>("Quantity") < 0)
                {
                    throw new AfwException("تعداد کالای وارد شده در سطر {0} مجاز نمی باشد.",
                                           entity.GetFieldValue <int>("RowNumber"));
                }
                else if (entity.GetFieldValue <int>("Quantity") == 0)
                {
                    //تنها در رسید و حواله تغییر ارزش تعداد 0 مجاز است و در این حالت هم نباید شماره بچ و وضعیت وارد شود
                    if (!string.IsNullOrEmpty(entity.GetFieldValue <string>("BatchNumber")) || entity.GetFieldValue <Guid?>("StuffStatus") != null)
                    {
                        throw new AfwException("تعداد کالای وارد شده در سطر {0} مجاز نمی باشد.",
                                               entity.GetFieldValue <int>("RowNumber"));
                    }
                }

                if (!dbHelper.EntityExists("cmn.StuffPossibleLocation", string.Format("StuffDef = '{0}' and StuffLocation = '{1}'",
                                                                                      stuff.GetFieldValue <Guid>("StuffDef"), stuffLocationID)))
                {
                    throw new AfwException("در تعریف کالای سطر {0}، {1} بعنوان انبار مجاز انتخاب نشده است.",
                                           entity.GetFieldValue <int>("RowNumber"), stuffLocation.GetFieldValue <string>("Name"));
                }

                new GhabzOrHavaleItemBL().ValidateBatchNumbers(entity);
            }
        }
Esempio n. 15
0
        private bool ValidateAccDocAccounts(Entity entity)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            if (entity.GetFieldValue <decimal>("GeneralDiscount") != 0)
            {
                throw new AfwException("GeneralDiscount has value. not Implemented.");
            }

            var financialGroupID = entity.GetFieldValue <Guid>("FinancialGroup");

            var financialGroupEntity = dbHelper.FetchSingleByID("cmn.FinancialGroup", financialGroupID, null);

            if (financialGroupEntity == null)
            {
                return(false);
            }

            string docGenerationMethod          = OptionSetHelper.GetOptionSetItemName(financialGroupEntity.GetFieldValue <Guid>("BuyDocGenerationMethod"));
            var    hesabeKharid                 = financialGroupEntity.GetFieldValue <Guid?>("ShabloneSanad_HesabeKharid");
            var    hesabeTaminKonandegan        = financialGroupEntity.GetFieldValue <Guid?>("ShabloneSanad_HesabeTaminKonandegan");
            var    hesabeAvarezBarArzeshAfzoode = financialGroupEntity.GetFieldValue <Guid?>("ShabloneSanad_HesabeAvarezBarArzeshAfzoode_Kharid");
            var    hesabeMaliatBarArzeshAfzoode = financialGroupEntity.GetFieldValue <Guid?>("ShabloneSanad_HesabeMaliatBarArzeshAfzoode_Kharid");
            var    hesabeTakhfifat              = financialGroupEntity.GetFieldValue <Guid?>("ShabloneSanad_HesabeTakhfifat_Kharid");

            if ((docGenerationMethod == "TakhfifDarSanadJodaShavad" &&
                 (hesabeKharid == null ||
                  hesabeTaminKonandegan == null ||
                  hesabeAvarezBarArzeshAfzoode == null ||
                  hesabeMaliatBarArzeshAfzoode == null ||
                  hesabeTakhfifat == null))
                ||
                (docGenerationMethod == "TakhfifDarSanadJodaNashavad" &&
                 (hesabeKharid == null ||
                  hesabeTaminKonandegan == null ||
                  hesabeAvarezBarArzeshAfzoode == null ||
                  hesabeMaliatBarArzeshAfzoode == null))
                )
            {
                return(false);
            }

            var query           = string.Format(@"
                select Service.ID , Service.Name
                from ps_BuyInvoiceItems Item
                    inner join cmn_Services Service on Service.ID = Item.Service
                where Item.BuyInvoice = '{0}' ", entity.GetFieldValue <Guid>("ID"));
            var serviceEntities = dbHelper.FetchMultipleBySqlQuery(query).Entities;

            cmn.Instance.CheckServicesAccSetting(serviceEntities, entity.GetFieldValue <Guid>("FinancialYear"));

            return(true);
        }
Esempio n. 16
0
        public EntityList GetUserReminderItems()
        {
            var core = CoreComponent.Instance;

            var filterExpression = string.Format("ReminderTime is not null and ReminderTime <= '{0}'", core.GetServerDateTime());

            filterExpression += string.Format(" and ActivityStatus = '{0}'", OptionSetHelper.GetOptionSetItemID("cmn.ActivityStatuses", "NotCompleted"));
            filterExpression += string.Format(" and OwnerUser = '******'", core.CurrentSession.GetFieldValue <Guid>("SystemUser"));

            var result = core.MainDbHelper.FetchMultiple("cmn_ActivitiesView", filterExpression, "ReminderTime", null, null, null);

            return(result);
        }
Esempio n. 17
0
        public void SaveNewConnectedPerson(Entity personConnectedPerson)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            var name            = personConnectedPerson.GetFieldValue <string>("Name");
            var lastName        = personConnectedPerson.GetFieldValue <string>("LastName");
            var gender          = personConnectedPerson.GetFieldValue <Guid?>("Gender");
            var workPhoneNumber = personConnectedPerson.GetFieldValue <string>("WorkPhoneNumber");
            var faxNumber       = personConnectedPerson.GetFieldValue <string>("FaxNumber");
            var mobileNumber1   = personConnectedPerson.GetFieldValue <string>("MobileNumber1");
            var mobileNumber2   = personConnectedPerson.GetFieldValue <string>("MobileNumber2");
            var email           = personConnectedPerson.GetFieldValue <string>("Email");

            personConnectedPerson.RemoveField("Name");
            personConnectedPerson.RemoveField("LastName");
            personConnectedPerson.RemoveField("Gender");
            personConnectedPerson.RemoveField("WorkPhoneNumber");
            personConnectedPerson.RemoveField("FaxNumber");
            personConnectedPerson.RemoveField("MobileNumber1");
            personConnectedPerson.RemoveField("MobileNumber2");
            personConnectedPerson.RemoveField("Email");

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                var connectedPerson = dbHelper.CreateNewEntity("cmn.Person");
                connectedPerson.SetFieldValue("PersonType", OptionSetHelper.GetOptionSetItemID("cmn.PersonTypes", "Haghighi"));
                connectedPerson.SetFieldValue("Name", name);
                connectedPerson.SetFieldValue("LastName", lastName);
                connectedPerson.SetFieldValue("Gender", gender);
                connectedPerson.SetFieldValue("WorkPhoneNumber", workPhoneNumber);
                connectedPerson.SetFieldValue("Fax", faxNumber);
                connectedPerson.SetFieldValue("MobilePhoneNumber1", mobileNumber1);
                connectedPerson.SetFieldValue("Email", email);
                dbHelper.InsertEntity(connectedPerson);

                if (!string.IsNullOrEmpty(mobileNumber2))
                {
                    var mobileNumber2Entity = dbHelper.CreateNewEntity("cmn.PhoneNumber");
                    mobileNumber2Entity.SetFieldValue("Person", connectedPerson.GetFieldValue <Guid>("ID"));
                    mobileNumber2Entity.SetFieldValue("TelType", OptionSetHelper.GetOptionSetItemID("cmn.PhoneType", "Mobile"));
                    mobileNumber2Entity.SetFieldValue("Phone", mobileNumber2);
                    dbHelper.InsertEntity(mobileNumber2Entity);
                }

                personConnectedPerson.SetFieldValue("ConnectedPerson", connectedPerson.GetFieldValue <Guid>("ID"));
                dbHelper.InsertEntity(personConnectedPerson);

                tranManager.Commit();
            }
        }
Esempio n. 18
0
        public override void AfterApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.AfterApplyChanges(dbHelper, entity);

            var salesCase = dbHelper.FetchSingleByID("crm.SalesCase", entity.GetFieldValue <Guid>("SalesCase"), null);

            if (entity.ChangeStatus.IsIn(EntityChangeTypes.Add))
            {
                var salesCaseStatus_LostID = OptionSetHelper.GetOptionSetItemID("crm.SalesCaseStatuses", "Lost");
                salesCase.FieldValues["Status"] = salesCaseStatus_LostID;
            }

            salesCase.FieldValues["LastActionTime"] = CoreComponent.Instance.GetServerDateTime();
            salesCase.ChangeStatus = EntityChangeTypes.Modify;

            dbHelper.ApplyChanges(salesCase);
        }
Esempio n. 19
0
        public Guid GetDefaultFinancialGroupID(Guid financialDocTypeID, Guid financialYearID, Guid organizationUnitID)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            var financialGroupEntity = dbHelper.FetchSingle("cmn.FinancialGroup",
                                                            string.Format(@"FinancialDocType = '{0}' and FinancialYear = '{1}' and OrganizationUnit = '{2}'",
                                                                          financialDocTypeID, financialYearID, organizationUnitID), null);

            if (financialGroupEntity == null)
            {
                var financialDocType = OptionSetHelper.GetOptionSetItemTitle(financialDocTypeID);
                var financialYear    = dbHelper.FetchSingleByID("cmn.FinancialYear", financialYearID, null);
                var organizationUnit = dbHelper.FetchSingleByID("cmn.OrganizationInformation", organizationUnitID, null);
                throw new AfwException("تنظیمات واحد سازمانی برای واحد {0} در سال مالی {1} و نوع سند مالی {2} موجود نیست.",
                                       organizationUnit.GetFieldValue <string>("Name"), financialYear.GetFieldValue <string>("YearNo"), financialDocType);
            }

            return(financialGroupEntity.GetFieldValue <Guid>("ID"));
        }
Esempio n. 20
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.IsIn(EntityChangeTypes.Add, EntityChangeTypes.Modify))
            {
                var chequeTypeName = OptionSetHelper.GetOptionSetItemName(entity.GetFieldValue <Guid>("ChequeType"));

                var filter = "";
                if (chequeTypeName == "Received")
                {
                    filter = string.Format(@"ReceivedChequeStatus is not null and ReceivedChequeStatus = '{0}' and AccountInCoding = '{1}' and FinancialYear = '{2}' and ID <> '{3}'",
                                           entity.GetFieldValue <Guid?>("ReceivedChequeStatus"),
                                           entity.GetFieldValue <Guid>("AccountInCoding"),
                                           entity.GetFieldValue <Guid>("FinancialYear"),
                                           entity.GetFieldValue <Guid>("ID"));
                }
                else if (chequeTypeName == "Paid")
                {
                    filter = string.Format(@"PaidChequeStatus is not null and PaidChequeStatus = '{0}' and AccountInCoding = '{1}' and FinancialYear = '{2}' and ID <> '{3}'",
                                           entity.GetFieldValue <Guid?>("PaidChequeStatus"),
                                           entity.GetFieldValue <Guid>("AccountInCoding"),
                                           entity.GetFieldValue <Guid>("FinancialYear"),
                                           entity.GetFieldValue <Guid>("ID"));
                }

                if (dbHelper.EntityExists("rp.ChequeStatusChangeAccSetting", filter))
                {
                    throw new AfwException("وضعیت تکراری است");
                }


                if ((chequeTypeName == "Received" && entity.GetFieldValue <Guid?>("ReceivedChequeStatus") == null) ||
                    (chequeTypeName == "Paid" && entity.GetFieldValue <Guid?>("PaidChequeStatus") == null))
                {
                    throw new AfwException("وضعیت مقدار ندارد");
                }
            }
        }
Esempio n. 22
0
        public override void BeforeApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.BeforeApplyChanges(dbHelper, entity);

            var oldAccDocEntity = dbHelper.FetchSingleByID("acc.AccDoc", entity.GetFieldValue <Guid>("AccDoc"), null);

            if (entity.ChangeStatus.IsIn(EntityChangeTypes.Delete, EntityChangeTypes.Modify))
            {
                if (oldAccDocEntity.GetFieldValue <Guid>("DocStatus") == OptionSetHelper.GetOptionSetItemID("acc.DocStatus", "Final"))
                {
                    throw new AfwException("امکان تغییر یا حذف آیتم سند قطعی شده وجود ندارد.");
                }
            }

            var exists = dbHelper.EntityExists("acc.Account",
                                               string.Format("ID = '{0}' and FinancialYear = '{1}'", entity.GetFieldValue <Guid>("Account"), oldAccDocEntity.GetFieldValue <Guid>("FinancialYear")));

            if (!exists)
            {
                throw new AfwException("کدینگ انتخاب شده با سال مالی جاری تطابق ندارد.");
            }

            var debtorAmount   = entity.GetFieldValue <decimal>("DebtorAmount");
            var creditorAmount = entity.GetFieldValue <decimal>("CreditorAmount");

            if (debtorAmount - Math.Truncate(debtorAmount) > 0)
            {
                throw new AfwException("مبلغ بدهکار در ردیف {0} سند {1} دارای اعشار است.{2}",
                                       entity.GetFieldValue <int>("RowNo"), oldAccDocEntity.GetFieldValue <int>("DocNo"), debtorAmount);
            }

            if (creditorAmount - Math.Truncate(creditorAmount) > 0)
            {
                throw new AfwException("مبلغ بستانکار در ردیف {0} سند {1} دارای اعشار است.{2}",
                                       entity.GetFieldValue <int>("RowNo"), oldAccDocEntity.GetFieldValue <int>("DocNo"), creditorAmount);
            }
        }
Esempio n. 23
0
        private List <Entity> GroupItemsByStuffLocationAndGhabzOrHavaleType(List <Entity> warehouseHybridOperationItems)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            List <Entity> groupsList = new List <Entity>();

            var stuffLocations     = dbHelper.FetchMultiple("cmn.StuffLocation", null, null, null, null, null).Entities;
            var ghabzOrHavaleTypes = wm.Instance.CachedGhabzOrHavaleTypes;

            foreach (var stuffLocation in stuffLocations)
            {
                foreach (var ghabzOrHavaleType in ghabzOrHavaleTypes)
                {
                    var groupItems = warehouseHybridOperationItems.FindAll(o =>
                                                                           o.GetFieldValue <Guid>("StuffLocation") == stuffLocation.GetFieldValue <Guid>("ID") &&
                                                                           o.GetFieldValue <Guid>("GhabzOrHavaleType") == ghabzOrHavaleType.GetFieldValue <Guid>("ID"));

                    if (groupItems.Count > 0)
                    {
                        var group = new Entity();

                        var isGhabz = wm.Instance.GetGhabzOrHavaleTypeEntity(ghabzOrHavaleType.GetFieldValue <Guid>("ID"))
                                      .GetFieldValue <Guid>("WarehouseDocType") == OptionSetHelper.GetOptionSetItemID("cmn.WarehouseDocType", "Ghabz");

                        group.AddField("IsGhabz", isGhabz);
                        group.AddField("StuffLocation", stuffLocation.GetFieldValue <Guid>("ID"));
                        group.AddField("GhabzOrHavaleType", ghabzOrHavaleType.GetFieldValue <Guid>("ID"));
                        group.AddField("Items", groupItems);

                        groupsList.Add(group);
                    }
                }
            }

            return(groupsList);
        }
Esempio n. 24
0
        public void DisqualifyLead(Entity disqualifyInfo)
        {
            //DebugHelper.Break();
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                var disqualified = OptionSetHelper.GetOptionSetItemID("crm.LeadQualificationStatus", "Disqualified");

                var leadEntity = dbHelper.FetchSingle("crm.Lead", string.Format("ID = '{0}'", disqualifyInfo.GetFieldValue <Guid>("Lead")), null);
                var leadQualificationStatus = leadEntity.GetFieldValue <Guid?>("QualificationStatus");

                if (leadQualificationStatus == disqualified)
                {
                    throw new AfwException("این سرنخ تجاری قبلاً تجاری رد شده است.");
                }

                leadEntity.SetFieldValue("QualificationStatus", disqualified);
                dbHelper.UpdateEntity(leadEntity);
                dbHelper.InsertEntity(disqualifyInfo);

                tranManager.Commit();
            }
        }
Esempio n. 25
0
        private void SetAccDocToWarehouseDocs(Guid accDocID, Guid financialDocType, Guid organizationUnit, Guid financialYearID, DateTime issueDate)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            var vazeyatRialiShodeID      = OptionSetHelper.GetOptionSetItemID("wm.VaziyatRialiAsnadAnbar", "RialiShode");
            var vazeyatRialiSanadShodeID = OptionSetHelper.GetOptionSetItemID("wm.VaziyatRialiAsnadAnbar", "SanadShode");

            string filterExpression = string.Format(@"FinancialYear = '{0}' and
		                OrganizationUnit = '{1}' and
		                FinancialDocType = '{2}' and
		                VazeyatRialiShodan = '{3}' and
                        IssueDate = '{4}' ",
                                                    financialYearID, organizationUnit, financialDocType, vazeyatRialiShodeID, issueDate);

            var ghabzOrHavaleEntities = dbHelper.FetchMultiple("wm.GhabzOrHavale", filterExpression, null, null, null, null).Entities;

            for (int i = 0; i < ghabzOrHavaleEntities.Count; i++)
            {
                ghabzOrHavaleEntities[i].ChangeStatus = "Modify";
                ghabzOrHavaleEntities[i].SetFieldValue("AccDoc", accDocID);
                ghabzOrHavaleEntities[i].SetFieldValue("VazeyatRialiShodan", vazeyatRialiSanadShodeID);
                dbHelper.UpdateEntity(ghabzOrHavaleEntities[i]);
            }
        }
Esempio n. 26
0
        public void FinalSaveReceiveReceipt(Entity entity)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                try
                {
                    dbHelper.ApplyChanges(entity);

                    var automaticAccDocSettingName = rp.Instance.GetAutomaticAccDocSetting("ReceiveReceipt");
                    if (automaticAccDocSettingName != "Disabled")
                    {
                        var receiveReceiptID   = entity.GetFieldValue <Guid>("ID");
                        var issueDate          = entity.GetFieldValue <DateTime>("ReceiptDate");
                        var financialYear      = entity.GetFieldValue <Guid>("FinancialYear");
                        var financialDocTypeID = entity.GetFieldValue <Guid>("FinancialDocType");
                        var organizationUnitID = entity.GetFieldValue <Guid>("OrganizationUnit");
                        var receiptTypeID      = entity.GetFieldValue <Guid>("ReceiptType");
                        var receiptTypeName    = OptionSetHelper.GetOptionSetItemName(receiptTypeID);
                        var financialGroup     = entity.GetFieldValue <Guid>("FinancialGroup");
                        var desc     = "بابت رسید دریافت شماره " + entity.GetFieldValue <string>("ReceiptNumber");
                        var accDocID = entity.GetFieldValue <Guid?>("AccDoc");

                        if (accDocID == null && automaticAccDocSettingName == "ByDay")
                        {
                            if (receiptTypeName == "Varzesh")
                            {
                                accDocID = acc.Instance.GetTodayAccDoc("SportAutomationReceiveReceipt", financialDocTypeID, issueDate, organizationUnitID);
                            }
                            else
                            {
                                accDocID = acc.Instance.GetTodayAccDoc("ReceiveReceipt", financialDocTypeID, issueDate, organizationUnitID);
                            }
                        }

                        if (receiptTypeName == "Varzesh")
                        {
                            acc.Instance.InsertOrUpdateAccDocMaster(ref accDocID, "SportAutomationReceiveReceipt", issueDate, financialYear, financialGroup, desc, true);
                        }
                        else
                        {
                            acc.Instance.InsertOrUpdateAccDocMaster(ref accDocID, "ReceiveReceipt", issueDate, financialYear, financialGroup, desc, true);
                        }

                        if (entity.GetFieldValue <Guid?>("AccDoc") == null)
                        {
                            entity.SetFieldValue("AccDoc", accDocID);
                            dbHelper.UpdateEntity(entity);
                        }

                        CreateOrUpdateReceiveReceiptAccDocItems(entity, (Guid)accDocID);

                        tranManager.Commit();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("خطا در عملیات ثبت نهایی.\r\n", ex);
                }
            }
        }
Esempio n. 27
0
        private void CreateReturnFromBuyAccDocItems(Entity entity, Guid accDocID)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            if (entity.GetFieldValue <decimal>("GeneralDiscount") != 0)
            {
                throw new AfwException("GeneralDiscount has value. not Implemented.");
            }

            var           opFieldNameInItemEntity = "RefOp_ReturnFromBuy";
            List <Entity> accDocItemList          = new List <Entity>();

            var invoiceID           = entity.GetFieldValue <Guid>("ID");
            var returnFromBuyNumber = entity.GetFieldValue <string>("ReturnFromBuyNumber");
            var seller          = entity.GetFieldValue <Guid>("Seller");
            var finalAmount     = entity.GetFieldValue <decimal>("FinalAmount");
            var totalTaxAndToll = entity.GetFieldValue <decimal>("TotalTaxAndToll");
            var discountAmount  = entity.GetFieldValue <decimal>("TotalDiscount");

            var sellerEntity = dbHelper.FetchSingle("cmn.Person", string.Format("ID = '{0}'", seller), null);
            var itemDesc     = "برگشت از خرید - خدمات طی فاکتور شماره " + returnFromBuyNumber + " به شخص " + sellerEntity.GetFieldValue <string>("StoredDisplayText");

            var    financialGroupID     = entity.GetFieldValue <Guid>("FinancialGroup");
            var    financialGroupEntity = dbHelper.FetchSingleByID("cmn.FinancialGroup", financialGroupID, null);
            string docGenerationMethod  = OptionSetHelper.GetOptionSetItemName(financialGroupEntity.GetFieldValue <Guid>("BuyDocGenerationMethod"));

            var hesabeBargashtAzKharid       = financialGroupEntity.GetFieldValue <Guid?>("ShabloneSanad_HesabeBargashtAzKharid");
            var hesabeTaminKonandegan        = financialGroupEntity.GetFieldValue <Guid?>("ShabloneSanad_HesabeTaminKonandegan");
            var hesabeAvarezBarArzeshAfzoode = financialGroupEntity.GetFieldValue <Guid?>("ShabloneSanad_HesabeAvarezBarArzeshAfzoode_Kharid");
            var hesabeMaliatBarArzeshAfzoode = financialGroupEntity.GetFieldValue <Guid?>("ShabloneSanad_HesabeMaliatBarArzeshAfzoode_Kharid");
            var hesabeTakhfifat = financialGroupEntity.GetFieldValue <Guid?>("ShabloneSanad_HesabeTakhfifat_Kharid");

            acc.Instance.DeleteAccDocItems(accDocID, opFieldNameInItemEntity, invoiceID);

            //آیتمهای بدهکار**
            //تامین کننده*********************
            {
                var accDocItemEntity = new Entity();
                accDocItemEntity.AddField("accountID", (Guid)hesabeTaminKonandegan);
                accDocItemEntity.AddField("personID", seller);
                accDocItemEntity.AddField("costCenterID", null);
                accDocItemEntity.AddField("projectID", null);
                accDocItemEntity.AddField("foreignCurrencyID", null);
                accDocItemEntity.AddField("note", itemDesc);
                accDocItemEntity.AddField("creditorAmount", 0);
                accDocItemEntity.AddField("debtorAmount", finalAmount);
                accDocItemEntity.AddField("isActive", true);

                accDocItemList.Add(accDocItemEntity);
            }
            //************************/

            //تخفیف******************
            if (docGenerationMethod == "TakhfifDarSanadJodaShavad" && discountAmount > 0)
            {
                var accDocItemEntity = new Entity();
                accDocItemEntity.AddField("accountID", (Guid)hesabeTakhfifat);
                accDocItemEntity.AddField("personID", null);
                accDocItemEntity.AddField("costCenterID", null);
                accDocItemEntity.AddField("projectID", null);
                accDocItemEntity.AddField("foreignCurrencyID", null);
                accDocItemEntity.AddField("note", itemDesc + "(تخفیف)");
                accDocItemEntity.AddField("creditorAmount", 0);
                accDocItemEntity.AddField("debtorAmount", discountAmount);
                accDocItemEntity.AddField("isActive", true);

                accDocItemList.Add(accDocItemEntity);
            }
            //************************/

            //آیتمهای بستانکار*******************************************************************************************************
            //کالاها******************
            var stuffsEntity = dbHelper.FetchSingleBySqlQuery(string.Format(@"
                    select sum(TotalPrice),
                        sum(Discount) Discount
                    from ps_ReturnFromBuyItems
                    where ReturnFromBuy = '{0}' and Stuff is not null", invoiceID));

            if (stuffsEntity != null && stuffsEntity.GetFieldValue <decimal?>("TotalPrice") != null)
            {
                var stuffsTotalPrice = stuffsEntity.GetFieldValue <decimal>("TotalPrice");
                var stuffsDiscount   = stuffsEntity.GetFieldValue <decimal>("Discount");
                var buyAmount        = stuffsTotalPrice;

                if (docGenerationMethod == "TakhfifDarSanadJodaNashavad")
                {
                    buyAmount -= discountAmount;
                }

                var accDocItemEntity = new Entity();
                accDocItemEntity.AddField("accountID", (Guid)hesabeBargashtAzKharid);
                accDocItemEntity.AddField("personID", null);
                accDocItemEntity.AddField("costCenterID", null);
                accDocItemEntity.AddField("projectID", null);
                accDocItemEntity.AddField("foreignCurrencyID", null);
                accDocItemEntity.AddField("note", itemDesc + "(کالاها)");
                accDocItemEntity.AddField("creditorAmount", buyAmount);
                accDocItemEntity.AddField("debtorAmount", 0);
                accDocItemEntity.AddField("isActive", true);

                accDocItemList.Add(accDocItemEntity);
            }

            //مالیات عوارض******************
            if (totalTaxAndToll > 0)
            {
                decimal totalTax;
                decimal totalToll;
                GetTotalTaxToll(entity, out totalTax, out totalToll);

                if (totalTax > 0)
                {
                    var accDocItemEntity = new Entity();
                    accDocItemEntity.AddField("accountID", (Guid)hesabeMaliatBarArzeshAfzoode);
                    accDocItemEntity.AddField("personID", null);
                    accDocItemEntity.AddField("costCenterID", null);
                    accDocItemEntity.AddField("projectID", null);
                    accDocItemEntity.AddField("foreignCurrencyID", null);
                    accDocItemEntity.AddField("note", itemDesc + "(مالیات)");
                    accDocItemEntity.AddField("creditorAmount", totalTax);
                    accDocItemEntity.AddField("debtorAmount", 0);
                    accDocItemEntity.AddField("isActive", true);

                    accDocItemList.Add(accDocItemEntity);
                }

                if (totalToll > 0)
                {
                    var accDocItemEntity = new Entity();
                    accDocItemEntity.AddField("accountID", (Guid)hesabeAvarezBarArzeshAfzoode);
                    accDocItemEntity.AddField("personID", null);
                    accDocItemEntity.AddField("costCenterID", null);
                    accDocItemEntity.AddField("projectID", null);
                    accDocItemEntity.AddField("foreignCurrencyID", null);
                    accDocItemEntity.AddField("note", itemDesc + "(عوارض)");
                    accDocItemEntity.AddField("creditorAmount", totalToll);
                    accDocItemEntity.AddField("debtorAmount", 0);
                    accDocItemEntity.AddField("isActive", true);

                    accDocItemList.Add(accDocItemEntity);
                }
            }

            acc.Instance.InsertAccDocItems(accDocID, opFieldNameInItemEntity, invoiceID, accDocItemList);
            //************************/
        }
Esempio n. 28
0
        private void CreateBuyInvoiceAccDocItems(Entity entity, Guid accDocID)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            if (entity.GetFieldValue <decimal>("GeneralDiscount") != 0)
            {
                throw new AfwException("GeneralDiscount has value. not Implemented.");
            }

            var           opFieldNameInItemEntity = "RefOp_BuyInvoice";
            List <Entity> accDocItemList          = new List <Entity>();

            var invoiceId       = entity.GetFieldValue <Guid>("ID");
            var seller          = entity.GetFieldValue <Guid>("Seller");
            var finalAmount     = entity.GetFieldValue <decimal>("FinalAmount");
            var totalTaxAndToll = entity.GetFieldValue <decimal>("TotalTaxAndToll");
            var discountAmount  = entity.GetFieldValue <decimal>("TotalDiscount");

            acc.Instance.DeleteAccDocItems(accDocID, opFieldNameInItemEntity, invoiceId);

            var    financialGroupID             = entity.GetFieldValue <Guid>("FinancialGroup");
            var    financialGroupEntity         = dbHelper.FetchSingleByID("cmn.FinancialGroup", financialGroupID, null);
            string docGenerationMethod          = OptionSetHelper.GetOptionSetItemName(financialGroupEntity.GetFieldValue <Guid>("BuyDocGenerationMethod"));
            Guid   hesabeKharid                 = financialGroupEntity.GetFieldValue <Guid>("ShabloneSanad_HesabeKharid");
            Guid   hesabeTaminKonandegan        = financialGroupEntity.GetFieldValue <Guid>("ShabloneSanad_HesabeTaminKonandegan");
            Guid   hesabeAvarezBarArzeshAfzoode = financialGroupEntity.GetFieldValue <Guid>("ShabloneSanad_HesabeAvarezBarArzeshAfzoode_Kharid");
            Guid   hesabeMaliatBarArzeshAfzoode = financialGroupEntity.GetFieldValue <Guid>("ShabloneSanad_HesabeMaliatBarArzeshAfzoode_Kharid");
            Guid   hesabeTakhfifat              = financialGroupEntity.GetFieldValue <Guid>("ShabloneSanad_HesabeTakhfifat_Kharid");

            //آیتمهای بدهکار *******************************************************************************************************
            //کالاها******************
            var stuffsEntity = dbHelper.FetchSingleBySqlQuery(string.Format(@"
                select sum(TotalPrice) TotalPrice,
                    sum(Discount) Discount
                from ps_BuyInvoiceItems
                where BuyInvoice = '{0}' and Stuff is not null", invoiceId));

            if (stuffsEntity != null && stuffsEntity.GetFieldValue <decimal?>("TotalPrice") != null)
            {
                var stuffsTotalPrice = stuffsEntity.GetFieldValue <decimal>("TotalPrice");
                var stuffsDiscount   = stuffsEntity.GetFieldValue <decimal>("Discount");
                var buyAmount        = stuffsTotalPrice;

                if (docGenerationMethod == "TakhfifDarSanadJodaNashavad")
                {
                    buyAmount -= discountAmount;
                }

                var accDocItemEntity = new Entity();
                accDocItemEntity.AddField("accountID", hesabeKharid);
                accDocItemEntity.AddField("personID", null);
                accDocItemEntity.AddField("costCenterID", null);
                accDocItemEntity.AddField("projectID", null);
                accDocItemEntity.AddField("foreignCurrencyID", null);
                accDocItemEntity.AddField("note", "خرید");
                accDocItemEntity.AddField("creditorAmount", 0);
                accDocItemEntity.AddField("debtorAmount", (decimal)buyAmount);
                accDocItemEntity.AddField("isActive", true);

                accDocItemList.Add(accDocItemEntity);
            }

            //خدمات******************

            var services = dbHelper.FetchMultipleBySqlQuery(
                string.Format(@"
                    select AccSetting.Account Account, 
                        sum(Item.TotalPrice) TotalPrice,
                        sum(Item.Discount) Discount
                    from ps_BuyInvoiceItems Item
                        inner join cmn_Services Service on Service.ID = Item.Service
	                    left join cmn_ServiceAccSettings AccSetting on AccSetting.Service = Service.ID
                    where Item.BuyInvoice = '{0}' and AccSetting.FinancialYear = '{1}'
                    group by AccSetting.Account",
                              entity.GetFieldValue <Guid?>("ID"),
                              entity.GetFieldValue <Guid>("FinancialYear")
                              )).Entities;

            foreach (var service in services)
            {
                var serviceTotalPrice = service.GetFieldValue <decimal>("TotalPrice");
                var serviceDiscount   = service.GetFieldValue <decimal>("Discount");
                var serviceAmount     = serviceTotalPrice;

                if (docGenerationMethod == "TakhfifDarSanadJodaNashavad")
                {
                    serviceAmount -= serviceDiscount;
                }

                var account = service.GetFieldValue <Guid>("Account");

                var accDocItemEntity = new Entity();
                accDocItemEntity.AddField("accountID", account);
                accDocItemEntity.AddField("personID", null);
                accDocItemEntity.AddField("costCenterID", null);
                accDocItemEntity.AddField("projectID", null);
                accDocItemEntity.AddField("foreignCurrencyID", null);
                accDocItemEntity.AddField("note", "خدمات");
                accDocItemEntity.AddField("creditorAmount", 0);
                accDocItemEntity.AddField("debtorAmount", serviceAmount);
                accDocItemEntity.AddField("isActive", true);

                accDocItemList.Add(accDocItemEntity);
            }

            //مالیات عوارض******************
            if (totalTaxAndToll > 0)
            {
                decimal totalTax;
                decimal totalToll;
                GetTotalTaxToll(entity, out totalTax, out totalToll);

                if (totalTax > 0)
                {
                    var accDocItemEntity = new Entity();
                    accDocItemEntity.AddField("accountID", hesabeMaliatBarArzeshAfzoode);
                    accDocItemEntity.AddField("personID", null);
                    accDocItemEntity.AddField("costCenterID", null);
                    accDocItemEntity.AddField("projectID", null);
                    accDocItemEntity.AddField("foreignCurrencyID", null);
                    accDocItemEntity.AddField("note", "مالیات");
                    accDocItemEntity.AddField("creditorAmount", 0);
                    accDocItemEntity.AddField("debtorAmount", totalTax);
                    accDocItemEntity.AddField("isActive", true);

                    accDocItemList.Add(accDocItemEntity);
                }

                if (totalToll > 0)
                {
                    var accDocItemEntity = new Entity();
                    accDocItemEntity.AddField("accountID", hesabeAvarezBarArzeshAfzoode);
                    accDocItemEntity.AddField("personID", null);
                    accDocItemEntity.AddField("costCenterID", null);
                    accDocItemEntity.AddField("projectID", null);
                    accDocItemEntity.AddField("foreignCurrencyID", null);
                    accDocItemEntity.AddField("note", "عوارض");
                    accDocItemEntity.AddField("creditorAmount", 0);
                    accDocItemEntity.AddField("debtorAmount", totalToll);
                    accDocItemEntity.AddField("isActive", true);

                    accDocItemList.Add(accDocItemEntity);
                }
            }

            //آیتمهای بستانکار**
            //تامین کننده***
            {
                var accDocItemEntity = new Entity();
                accDocItemEntity.AddField("accountID", hesabeTaminKonandegan);
                accDocItemEntity.AddField("personID", seller);
                accDocItemEntity.AddField("costCenterID", null);
                accDocItemEntity.AddField("projectID", null);
                accDocItemEntity.AddField("foreignCurrencyID", null);
                accDocItemEntity.AddField("note", "فاکتور خرید");
                accDocItemEntity.AddField("creditorAmount", finalAmount);
                accDocItemEntity.AddField("debtorAmount", 0);
                accDocItemEntity.AddField("isActive", true);

                accDocItemList.Add(accDocItemEntity);
            }

            //تخفیف***
            if (docGenerationMethod == "TakhfifDarSanadJodaShavad" && discountAmount > 0)
            {
                var accDocItemEntity = new Entity();
                accDocItemEntity.AddField("accountID", hesabeTakhfifat);
                accDocItemEntity.AddField("personID", null);
                accDocItemEntity.AddField("costCenterID", null);
                accDocItemEntity.AddField("projectID", null);
                accDocItemEntity.AddField("foreignCurrencyID", null);
                accDocItemEntity.AddField("note", "تخفیف");
                accDocItemEntity.AddField("creditorAmount", discountAmount);
                accDocItemEntity.AddField("debtorAmount", 0);
                accDocItemEntity.AddField("isActive", true);

                accDocItemList.Add(accDocItemEntity);
            }

            acc.Instance.InsertAccDocItems(accDocID, opFieldNameInItemEntity, invoiceId, accDocItemList);
        }
Esempio n. 29
0
        public Entity FetchOrCreatePerson(string personCode, string name, string lastName, string mobilePhoneNumber1OrCommission, string roleName, EntityDbHelper dbHelper)
        {
            var personExists = false;

            if (roleName == "Customer")
            {
                personExists = dbHelper.EntityExists("cmn.Person", string.Format("Name = N'{0}' and LastName = N'{1}' and MobilePhoneNumber1 = '{2}'", name, lastName, mobilePhoneNumber1OrCommission));
            }
            else if (roleName == "Marketer")
            {
                personExists = dbHelper.EntityExists("cmn.Person", string.Format("Name = N'{0}' and LastName = N'{1}'", name, lastName));
            }

            if (personExists == false)
            {
                var personEntity = dbHelper.CreateNewEntity("cmn.Person");
                personEntity.SetFieldValue("Name", name);
                personEntity.SetFieldValue("LastName", lastName);
                if (roleName == "Customer")
                {
                    personEntity.SetFieldValue("MobilePhoneNumber1", mobilePhoneNumber1OrCommission);
                }

                var haghighiID = OptionSetHelper.GetOptionSetItemID("cmn.PersonTypes", "Haghighi");
                personEntity.SetFieldValue("PersonType", haghighiID);

                var person_CustomerInfoEntity = dbHelper.CreateNewEntity("cmn.Person_CustomerInfo");
                var person_MarketerInfoEntity = dbHelper.CreateNewEntity("cmn.Person_MarketerInfo");

                if (roleName == "Customer")
                {
                    person_CustomerInfoEntity.SetFieldValue("PersonCode", personCode);
                    person_CustomerInfoEntity.SetFieldValue("Person", personEntity.GetFieldValue <Guid>("ID"));

                    personEntity.AddField("CustomerInfo", person_CustomerInfoEntity);
                }
                else if (roleName == "Marketer")
                {
                    person_MarketerInfoEntity.SetFieldValue("PersonCode", personCode);
                    person_MarketerInfoEntity.SetFieldValue("Person", personEntity.GetFieldValue <Guid>("ID"));
                    person_MarketerInfoEntity.SetFieldValue("Commission", mobilePhoneNumber1OrCommission);

                    personEntity.AddField("MarketerInfo", person_MarketerInfoEntity);
                }

                var personRoleRelationEntityList = new EntityList();
                var personRoleRelationEntity     = dbHelper.CreateNewEntity("cmn.PersonRoleRelation");
                personRoleRelationEntityList.EntityDefID = personRoleRelationEntity.EntityDefID;
                var personRoleEntity = dbHelper.FetchSingle("cmn.PersonRole", string.Format("Name = '{0}'", roleName), null);
                personRoleRelationEntity.SetFieldValue("PersonRole", personRoleEntity.GetFieldValue <Guid>("ID"));
                personRoleRelationEntity.SetFieldValue("Person", personEntity.GetFieldValue <Guid>("ID"));
                personRoleRelationEntityList.Entities.Add(personRoleRelationEntity);

                personEntity.SetFieldValue("PersonRoleRelations", personRoleRelationEntityList);

                new PersonBL().SavePerson(personEntity);
                return(personEntity);
            }
            else
            {
                var personEntity = dbHelper.CreateNewEntity("cmn.Person");
                if (roleName == "Customer")
                {
                    personEntity = dbHelper.FetchSingle("cmn.Person", string.Format("Name = N'{0}' and LastName = N'{1}' and MobilePhoneNumber1 = '{2}'", name, lastName, mobilePhoneNumber1OrCommission), null);
                }
                else if (roleName == "Marketer")
                {
                    personEntity = dbHelper.FetchSingle("cmn.Person", string.Format("Name = N'{0}' and LastName = N'{1}'", name, lastName), null);
                }

                return(personEntity);
            }
        }
Esempio n. 30
0
        public override void AfterApplyChanges(EntityDbHelper dbHelper, Entity entity)
        {
            base.AfterApplyChanges(dbHelper, entity);

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

            var ghabzOrHavaleTypeEntity   = dbHelper.FetchSingleByID("wm.GhabzOrHavaleType", entity.GetFieldValue <Guid>("GhabzOrHavaleType"), null);
            var vazeyatRiali_SanadShodeID = OptionSetHelper.GetOptionSetItemID("wm.VaziyatRialiAsnadAnbar", "SanadShode");
            var id = entity.GetFieldValue <Guid>("ID");
            var warehouseDocType = ghabzOrHavaleTypeEntity.GetFieldValue <Guid>("WarehouseDocType");

            if (entity.ChangeStatus == EntityChangeTypes.Add)
            {
                if (dbHelper.AdoDbHelper.ExistsRow(string.Format(@"
                    select 1
                    from wm_GhabzOrHavaleha GhabzOrHavaleh
	                    inner join wm_GhabzOrHavaleTypes GhabzOrHavaleType on GhabzOrHavaleType.ID = GhabzOrHavaleh.GhabzOrHavaleType
                    where GhabzOrHavaleType.WarehouseDocType = '{0}' 
	                    and GhabzOrHavaleh.StuffLocation = '{1}'
                        and GhabzOrHavaleh.GhabzOrHavaleNumber = {2}
                        and GhabzOrHavaleh.ID <> '{3}'",
                                                                 warehouseDocType,
                                                                 entity.GetFieldValue <Guid>("StuffLocation"),
                                                                 entity.GetFieldValue <decimal>("GhabzOrHavaleNumber"),
                                                                 id)))
                {
                    throw new AfwException(string.Format("{0} دیگری با این شماره ثبت شده است.",
                                                         OptionSetHelper.GetOptionSetItemTitle(warehouseDocType)));
                }

                if (entity.GetFieldValue <Guid?>("RefDoc_SalesInvoice") != null)
                {
                    var refDoc_SalesInvoiceID = entity.GetFieldValue <Guid>("RefDoc_SalesInvoice");
                    var salesProformaInvoice  = dbHelper.FetchSingleByID("ps.SalesInvoice", refDoc_SalesInvoiceID, null);
                    salesProformaInvoice.SetFieldValue("HavaleIssuingStatus", OptionSetHelper.GetOptionSetItemID("cmn.HavaleIssuingStatus", "HavaleShodeh"));
                    dbHelper.UpdateEntity(salesProformaInvoice);
                }
            }

            if (entity.ChangeStatus == EntityChangeTypes.Delete)
            {
                if (entity.GetFieldValue <Guid?>("RefDoc_SalesInvoice") != null)
                {
                    var proformaID = entity.GetFieldValue <Guid>("RefDoc_SalesInvoice");

                    if (dbHelper.EntityExists("ps.SalesInvoice",
                                              string.Format("IsProforma = 0 and SourceProforma = '{0}'", proformaID)))
                    {
                        throw new AfwException(string.Format("بدلیل صدور فاکتور امکان حذف حواله وجود ندارد."));
                    }

                    var proforma = dbHelper.FetchSingleByID("ps.SalesInvoice", proformaID, null);
                    proforma.SetFieldValue("HavaleIssuingStatus", OptionSetHelper.GetOptionSetItemID("cmn.HavaleIssuingStatus", "HavaleNashodeh"));
                    dbHelper.UpdateEntity(proforma);
                }
            }

            if (entity.ChangeStatus != EntityChangeTypes.Delete)
            {
                if (entity.FieldExists("GhabzOrHavaleItems") && entity.GetFieldValue <EntityList>("GhabzOrHavaleItems") != null)
                {
                    SaveItems(entity, entity.GetFieldValue <EntityList>("GhabzOrHavaleItems"), ghabzOrHavaleTypeEntity);
                }

                if (!HasItem(id))
                {
                    throw new AfwException("سند انبار فاقد آیتم است.");
                }
            }

            if (!wm.Instance.IsEvaluatingDocsForValuation && !wm.Instance.IsRunningValuation && !wm.Instance.IsRunningUnvaluation &&
                entity.GetFieldValue <Guid>("VazeyatRialiShodan") != vazeyatRiali_SanadShodeID)
            {
                if (wm.Instance.InventoryValuationBL.ValuatedDocExistsAfter(
                        entity.GetFieldValue <DateTime>("IssueDate"), entity.GetFieldValue <DateTime>("CreationTime")))
                {
                    throw new AfwException("سند انبار ریالی شده بعد از این سند انبار موجود است.\r\n" +
                                           " ابتدا رسید /حواله های بعد از این سند انبار را به وضعیت ریالی نشده منتقل کنید.");
                }
            }
        }