Example #1
0
        public void DeleteCreatedActivity(string callID)
        {
            //DebugHelper.Break();
            using (var dbHelper = DbHelperFactory.CreateMainDbEntityDbHelper())
            {
                using (var tranManager = new DbTransactionManager(dbHelper))
                {
                    var receivedCallEntity = dbHelper.FetchSingle("cmn.ReceivedCall", string.Format("ID = '{0}'", callID), null);

                    if (receivedCallEntity.GetFieldValue <Guid?>("CreatedActivity") != null)
                    {
                        Guid activityID = receivedCallEntity.GetFieldValue <Guid>("CreatedActivity");

                        receivedCallEntity.SetFieldValue("SalesCase", null);
                        receivedCallEntity.SetFieldValue("DetectedCustomer", null);
                        receivedCallEntity.SetFieldValue("CreatedActivity", null);
                        receivedCallEntity.ChangeStatus = "Modify";

                        dbHelper.ApplyChanges(receivedCallEntity);

                        var activityEntity = dbHelper.FetchSingle("cmn.Activity", string.Format("ID = '{0}'", activityID), null);
                        if (activityEntity != null)
                        {
                            activityEntity.ChangeStatus = "Delete";
                            dbHelper.ApplyChanges(activityEntity);
                        }
                    }

                    tranManager.Commit();
                }
            }
        }
Example #2
0
        public void UpdateAccDocItems(Guid receiveReceiptID)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                try
                {
                    var automaticAccDocSettingName = rp.Instance.GetAutomaticAccDocSetting("ReceiveReceipt");
                    if (automaticAccDocSettingName != "Disabled")
                    {
                        var receiveReceiptEntity = dbHelper.FetchSingleByID("rp.ReceiveReceipt", receiveReceiptID, null);
                        var accDocID             = receiveReceiptEntity.GetFieldValue <Guid?>("AccDoc");

                        CreateOrUpdateReceiveReceiptAccDocItems(receiveReceiptEntity, (Guid)accDocID);

                        tranManager.Commit();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("خطا در بروزرسانی سند حسابداری.\r\n", ex);
                }
            }
        }
Example #3
0
        public void SetRelatedContract(Guid receivedCallID, Guid contractId)
        {
            //DebugHelper.Break();

            using (var dbHelper = DbHelperFactory.CreateMainDbEntityDbHelper())
            {
                using (var tranManager = new DbTransactionManager(dbHelper))
                {
                    var receivedCallEntity = dbHelper.FetchSingle("cmn.ReceivedCall", string.Format("ID = '{0}'", receivedCallID), null);
                    var contractEntity     = dbHelper.FetchSingle("cmn.Contract", string.Format("ID = '{0}'", contractId), null);

                    if (receivedCallEntity.GetFieldValue <Guid?>("SalesCase") != null)
                    {
                        var salesCaseCustomerId = receivedCallEntity.GetFieldValue <Guid>("DetectedCustomer");
                        if (contractEntity.GetFieldValue <Guid>("Customer") != salesCaseCustomerId)
                        {
                            throw new AfwException("مشتری قرارداد با مشتری پرونده فروش متفاوت است.");
                        }
                    }
                    else
                    {
                        receivedCallEntity.SetFieldValue("DetectedCustomer", contractEntity.GetFieldValue <Guid>("Customer"));
                        receivedCallEntity.SetFieldValue("Contract", contractId);
                        dbHelper.ApplyChanges(receivedCallEntity);
                        receivedCallEntity.ChangeStatus = "Modify";
                        tranManager.Commit();
                    }
                }
            }
        }
Example #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();
                }
            }
        }
Example #5
0
        public void CreateChequeStatusChange(Guid chequeID, Guid newStatusID, Guid financialYearID, Guid?financialGroupID,
                                             DateTime changeDate, string description, bool generateAccDoc)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                Guid?previousChangeID = null;
                var  previousChange   = GetLastChequeStatusChange(chequeID);
                if (previousChange != null)
                {
                    previousChangeID = previousChange.GetFieldValue <Guid>("ID");
                }

                var paidChequeStatusChange = dbHelper.CreateNewEntity("rp.PaidChequeStatusChange");
                paidChequeStatusChange.SetFieldValue("Cheque", chequeID);
                paidChequeStatusChange.SetFieldValue("NewStatus", newStatusID);
                paidChequeStatusChange.SetFieldValue("PreviousStatusChange", previousChangeID);
                paidChequeStatusChange.SetFieldValue("ChangeDate", changeDate);
                paidChequeStatusChange.SetFieldValue("FinancialYear", financialYearID);
                paidChequeStatusChange.SetFieldValue("FinancialGroup", financialGroupID);
                paidChequeStatusChange.SetFieldValue("Description", description);
                dbHelper.ApplyChanges(paidChequeStatusChange);

                if (generateAccDoc)
                {
                    CreateChequeStatusChangeAccDoc(paidChequeStatusChange);
                }

                tranManager.Commit();
            }
        }
Example #6
0
        public void DeleteAccDocItems(Guid?accDocID, string opFieldNameInItemEntity, Guid?opID)
        {
            if (accDocID == null)
            {
                return;
            }

            var dbHelper = CoreComponent.Instance.MainDbHelper;

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                try
                {
                    var entities = dbHelper.FetchMultiple("acc_AccDocItems",
                                                          string.Format("AccDoc = '{0}' {1}", accDocID, opID == null ? "" : string.Format(" and {0} = '{1}'", opFieldNameInItemEntity, opID))
                                                          , null, null, null, null).Entities;

                    foreach (var entity in entities)
                    {
                        dbHelper.DeleteEntity(entity);
                    }

                    tranManager.Commit();
                }
                catch (Exception ex)
                {
                    throw new AfwException("Error In DeleteAccDoc", ex);
                }
            }
        }
Example #7
0
        public void CreateReturnFromSalesAccDoc(Entity entity)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            var automaticAccDocSettingName = rp.Instance.GetAutomaticAccDocSetting("SalesInvoice");

            if (automaticAccDocSettingName == "Disabled")
            {
                return;
            }

            if (String.IsNullOrEmpty(automaticAccDocSettingName))
            {
                throw new AfwException("تنظیمات سند حسابداری اتوماتیک فاکتور فروش تعیین نشده است");
            }

            if (!ValidateAccDocAccounts(entity))
            {
                throw new AfwException("کدینگ حساب های {0} در شابلون سند فروش مقداردهی نشده اند.",
                                       entity.GetFieldValue <bool>("IsAmani") == true ? "برگشت از امانی" : "برگشت از فروش");
            }

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                try
                {
                    var id                 = entity.GetFieldValue <Guid>("ID");
                    var issueDate          = entity.GetFieldValue <DateTime>("IssueDate");
                    var financialYear      = entity.GetFieldValue <Guid>("FinancialYear");
                    var financialDocTypeID = entity.GetFieldValue <Guid>("FinancialDocType");
                    var organizationUnitID = entity.GetFieldValue <Guid>("OrganizationUnit");
                    var financialGroupID   = entity.GetFieldValue <Guid>("FinancialGroup");
                    var desc               = "بابت برگشت از فروش به شماره  " + entity.GetFieldValue <string>("ReturnFromSalesNumber");
                    var accDocID           = entity.GetFieldValue <Guid?>("AccDoc");

                    if (accDocID == null && automaticAccDocSettingName == "ByDay")
                    {
                        accDocID = acc.Instance.GetTodayAccDoc("ReturnFromSalesInvoice", financialDocTypeID, issueDate, organizationUnitID);
                    }

                    acc.Instance.InsertOrUpdateAccDocMaster(ref accDocID, "ReturnFromSalesInvoice", issueDate, financialYear, financialGroupID, desc, true);

                    if (entity.GetFieldValue <Guid?>("AccDoc") == null)
                    {
                        dbHelper.AdoDbHelper.ExecuteNonQuery(string.Format(@"
                                update ps_ReturnFromSales set AccDoc = '{0}' where ID = '{1}'", accDocID, id));
                    }

                    CreateReturnFromSalesAccDocItems(entity, (Guid)accDocID);
                    acc.Instance.UpdateAccDocMasterBalanceStatus((Guid)accDocID);

                    tranManager.Commit();
                }
                catch (Exception ex)
                {
                    throw new Exception("Error In Acc Doc Auto Generate .\r\n" + ex.Message, ex);
                }
            }
        }
Example #8
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");
        }
Example #9
0
        public void SetSalesCaseActivity(Guid receivedCallID, Guid activityID)
        {
            using (var dbHelper = DbHelperFactory.CreateMainDbEntityDbHelper())
            {
                using (var tranManager = new DbTransactionManager(dbHelper))
                {
                    //DebugHelper.Break();

                    var receivedCall = dbHelper.FetchSingle("cmn.ReceivedCall", string.Format("ID = '{0}'", receivedCallID), null);

                    if (receivedCall.GetFieldValue <Guid?>("CallPerson") == null)
                    {
                        throw new AfwException("امکان ست کردن فعالیت برای تماس دریافتی که شخص تماس گیرنده آن تعیین نشده وجود ندارد.");
                    }

                    var activity = dbHelper.FetchSingle("cmn.Activity", string.Format("ID = '{0}'", activityID), null);

                    var callPersonID = receivedCall.GetFieldValue <Guid>("CallPerson");
                    var salesCaseID  = activity.GetFieldValue <Guid>("SalesCase");

                    var salesCase = dbHelper.FetchSingle("crm.SalesCase", string.Format("ID = '{0}'", salesCaseID), null);

                    if (receivedCall.GetFieldValue <Guid?>("Contract") != null)
                    {
                        var contractCustomerId = receivedCall.GetFieldValue <Guid>("DetectedCustomer");
                        if (salesCase.GetFieldValue <Guid>("Customer") != contractCustomerId)
                        {
                            throw new AfwException("مشتری پرونده فروش با مشتری قرارداد متفاوت است.");
                        }
                    }

                    receivedCall.SetFieldValue("SalesCase", salesCaseID);
                    receivedCall.SetFieldValue("DetectedCustomer", salesCase.GetFieldValue <Guid>("Customer"));

                    receivedCall.SetFieldValue("CreatedActivity", activityID);
                    receivedCall.ChangeStatus = "Modify";
                    dbHelper.ApplyChanges(receivedCall);

                    if (callPersonID != salesCase.GetFieldValue <Guid>("Customer"))
                    {
                        if (!dbHelper.EntityExists("crm.SalesCaseConnectedPerson",
                                                   string.Format("SalesCase = '{0}' and ConnectedPerson = '{1}'", salesCaseID, callPersonID)))
                        {
                            var salesCaseConnectedPerson = dbHelper.CreateNewEntity("crm.SalesCaseConnectedPerson");
                            salesCaseConnectedPerson.SetFieldValue("SalesCase", salesCaseID);
                            salesCaseConnectedPerson.SetFieldValue("ConnectedPerson", callPersonID);

                            dbHelper.ApplyChanges(salesCaseConnectedPerson);
                        }
                    }

                    tranManager.Commit();
                }
            }
        }
Example #10
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();
            }
        }
Example #11
0
        public void QualifyLead(Guid leadID)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                //DebugHelper.Break();
                var lead = dbHelper.FetchSingleByID("crm.Lead", leadID, null);

                ValidateLeadForQualify(lead);
                DoQualifyLead(lead);

                tranManager.Commit();
            }
        }
Example #12
0
        public Entity TankhahAccDocGenerate(bool repeatTotal, string tankhahID, string operationType, DateTime issueDate, string description)
        {
            Entity result = new Entity();

            result.FieldValues.Add("MaxDocNo", 0);
            result.FieldValues.Add("AccDocID", null);

            Int64 maxDocNo = 0;
            var   dbHelper = CoreComponent.Instance.MainDbHelper;

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                try
                {
                    var tankhahEntity = dbHelper.FetchSingle("rp.Tankhah", string.Format("ID = '{0}'", tankhahID), null);

                    var accDocID         = tankhahEntity.GetFieldValue <Guid?>("AccDoc");
                    var financialYear    = tankhahEntity.GetFieldValue <Guid>("FinancialYear");
                    var financialDocType = tankhahEntity.GetFieldValue <Guid>("FinancialDocType");
                    var organizationUnit = tankhahEntity.GetFieldValue <Guid>("OrganizationUnit");

                    acc.Instance.InsertAccDocMaster(ref accDocID, "Tankhah", issueDate, financialYear, financialDocType, organizationUnit, description, true);

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

                    CreateTankhahAccDocItems(tankhahEntity, (Guid)accDocID, repeatTotal);
                    acc.Instance.UpdateAccDocMasterBalanceStatus((Guid)accDocID);

                    maxDocNo = dbHelper.FetchSingle("acc.AccDoc", string.Format("ID = '{0}'", accDocID), null).GetFieldValue <Int64>("DocNo");

                    result.SetFieldValue("MaxDocNo", maxDocNo);
                    result.SetFieldValue("AccDocID", accDocID);

                    tranManager.Commit();

                    return(result);
                }
                catch (Exception ex)
                {
                    throw new AfwException("خطا در عملیات ثبت سند تنخواه.\r\n" + ex.Message);
                }
            }
        }
Example #13
0
        public void FinalSavePayReceipt(Entity entity)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

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

                    var automaticAccDocSettingName = rp.Instance.GetAutomaticAccDocSetting("PayReceipt");
                    if (automaticAccDocSettingName != "Disabled")
                    {
                        var payReceiptID       = 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 financialGroup     = entity.GetFieldValue <Guid>("FinancialGroup");
                        var desc     = "بابت رسید پرداخت شماره " + entity.GetFieldValue <string>("ReceiptNumber");
                        var accDocID = entity.GetFieldValue <Guid?>("AccDoc");

                        if (accDocID == null && automaticAccDocSettingName == "ByDay")
                        {
                            accDocID = acc.Instance.GetTodayAccDoc("PayReceipt", financialDocTypeID, issueDate, organizationUnitID);
                        }

                        acc.Instance.InsertOrUpdateAccDocMaster(ref accDocID, "PayReceipt", issueDate, financialYear, financialGroup, desc, true);

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

                        CreateOrUpdatePayReceiptAccDocItems(entity, (Guid)accDocID);

                        tranManager.Commit();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("مشکل در عملیات ثبت نهایی.", ex);
                }
            }
        }
Example #14
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();
            }
        }
Example #15
0
        public void InsertAccDocItems(Guid accDocID, string opFieldNameInItemEntity, Guid?opID, List <Entity> accDocItemList)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                foreach (var item in accDocItemList)
                {
                    var entity = dbHelper.CreateNewEntity("acc.AccDocItem");

                    if (opFieldNameInItemEntity == "RefOp_ClinicInvoice")
                    {
                        var clinicInvoice = dbHelper.FetchSingle("clin.ServiceInvoice", string.Format("ID = '{0}'", opID), null);
                        entity.SetFieldValue("OrganizationUnit", clinicInvoice.GetFieldValue <Guid?>("OrganizationUnit"));
                    }

                    entity.SetFieldValue("AccDoc", accDocID);
                    entity.SetFieldValue("RowNo", 1);
                    entity.SetFieldValue("Account", item.GetFieldValue <Guid>("accountID"));
                    entity.SetFieldValue("Person", item.GetFieldValue <Guid?>("personID"));
                    entity.SetFieldValue("CostCenter", item.GetFieldValue <Guid?>("costCenterID"));
                    entity.SetFieldValue("Project", item.GetFieldValue <Guid?>("projectID"));
                    entity.SetFieldValue("ForeignCurrency", item.GetFieldValue <Guid?>("foreignCurrencyID"));
                    entity.SetFieldValue("Note", item.GetFieldValue <string>("note"));
                    entity.SetFieldValue("CreditorAmount", item.GetFieldValue <decimal>("creditorAmount"));
                    entity.SetFieldValue("DebtorAmount", item.GetFieldValue <decimal>("debtorAmount"));
                    entity.SetFieldValue("IsActive", item.GetFieldValue <bool>("isActive"));

                    if (opID != null)
                    {
                        entity.SetFieldValue(opFieldNameInItemEntity, opID);
                    }

                    dbHelper.ApplyChanges(entity);
                }

                acc.Instance.UpdateAccDocMasterBalanceStatus(accDocID);

                tranManager.Commit();
            }
        }
Example #16
0
        private void CreateWarehouseAccDocItems(Guid accDocID, Guid financialDocType, Guid organizationUnit, Guid financialYearID, DateTime issueDate)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                try
                {
                    acc.Instance.DeleteAccDocItems(accDocID, "", null);
                    CreateGhabzAccDocItems(accDocID, financialDocType, organizationUnit, financialYearID, issueDate);
                    CreateHavaleAccDocItems(accDocID, financialDocType, organizationUnit, financialYearID, issueDate);
                    SetAccDocToWarehouseDocs(accDocID, financialDocType, organizationUnit, financialYearID, issueDate);

                    tranManager.Commit();
                }
                catch (Exception ex)
                {
                    throw new AfwException(ex.Message);
                }
            }
        }
Example #17
0
        public void DetectUndetectedCalls(string filterExpression, string sortExpression, int?startRecordNumber, int?pageSize)
        {
            //DebugHelper.Break();

            using (var dbHelper = DbHelperFactory.CreateMainDbEntityDbHelper())
            {
                using (var tranManager = new DbTransactionManager(dbHelper))
                {
                    var receivedCallsEntityList = dbHelper.FetchMultiple("cmn.ReceivedCall", filterExpression.Replace("Gregorian", ""), sortExpression, startRecordNumber, pageSize, null);

                    foreach (Entity receivedCall in receivedCallsEntityList.Entities)
                    {
                        if (receivedCall.GetFieldValue <Guid?>("CallPerson") == null)
                        {
                            DetectCallPerson(receivedCall);
                        }
                    }

                    tranManager.Commit();
                }
            }
        }
Example #18
0
        public void SaveItem(Entity ghabzOrHavale, Entity ghabzOrHavaleItem, Entity ghabzOrHavaleTypeEntity)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                var rowNumber = ghabzOrHavaleItem.GetFieldValue <Int64>("RowNumber");

                if (ghabzOrHavaleItem.GetFieldValue <Guid?>("Stuff") == null)
                {
                    return;
                }

                if (ghabzOrHavaleItem.GetFieldValue <int>("Quantity") < 0)
                {
                    throw new AfwException("تعدا کالا در سطر " + ghabzOrHavaleItem.GetFieldValue <int>("RowNumber") + " مجاز نمی باشد");
                }

                dbHelper.ApplyChanges(ghabzOrHavaleItem);

                tranManager.Commit();
            }
        }
Example #19
0
        //public void AddRoleToPerson(Guid personID, string roleName)
        //{
        //    var dbHelper = CoreComponent.Instance.MainDbHelper;

        //    var person = dbHelper.FetchSingleByID("cmn.Person", personID, new string[] { "PersonRoleRelations", "PersonGroupRelations" });

        //    if (!PersonHasRole(personID, roleName))
        //    {
        //        var roleID = GetPersonRoleID(roleName);

        //        var personRoleRelationEntity = dbHelper.CreateNewEntity("cmn.PersonRoleRelation");
        //        personRoleRelationEntity.SetFieldValue("Person", personID);
        //        personRoleRelationEntity.SetFieldValue("PersonRole", roleID);
        //        if (!person.FieldExists("PersonRoleRelations"))
        //        {
        //            var personRoleRelations = new EntityList();
        //            personRoleRelations.Entities.Add(personRoleRelationEntity);
        //            person.AddField("PersonRoleRelations", personRoleRelations);
        //        }
        //        else
        //            if (person.GetFieldValue<EntityList>("PersonRoleRelations") == null)
        //            {
        //                var personRoleRelations = new EntityList();
        //                personRoleRelations.Entities.Add(personRoleRelationEntity);
        //                person.SetFieldValue("PersonRoleRelations", personRoleRelations);
        //            }
        //            else
        //            {
        //                var personRoleRelations = person.GetFieldValue<EntityList>("PersonRoleRelations");
        //                personRoleRelations.Entities.Add(personRoleRelationEntity);
        //                person.SetFieldValue("PersonRoleRelations", personRoleRelations);
        //            }

        //        var roleInfoEntity = dbHelper.CreateNewEntity("cmn.Person_" + roleName + "Info");
        //        roleInfoEntity.SetFieldValue("Person", personID);
        //        person.AddField(roleName + "Info", roleInfoEntity);

        //        SavePerson(person);
        //    }

        //}

        public void AddRoleToPerson(Guid personID, string roleName)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                if (!PersonHasRole(personID, roleName))
                {
                    var personRole   = GetPersonRole(roleName);
                    var personRoleID = personRole.GetFieldValue <Guid>("ID");

                    var personRoleRelationEntity = dbHelper.CreateNewEntity("cmn.PersonRoleRelation");
                    personRoleRelationEntity.SetFieldValue("Person", personID);
                    personRoleRelationEntity.SetFieldValue("PersonRole", personRoleID);
                    dbHelper.ApplyChanges(personRoleRelationEntity);

                    var roleInfoEntity = dbHelper.CreateNewEntity("cmn.Person_" + roleName + "Info");
                    roleInfoEntity.SetFieldValue("Person", personID);
                    roleInfoEntity.SetFieldValue("PersonCode", GetNewPersonCode(roleName));
                    dbHelper.ApplyChanges(roleInfoEntity);

                    if (personRole.GetFieldValue <bool>("HasFinancialAccount"))
                    {
                        var person = dbHelper.FetchSingleByID("cmn.Person", personID, null);

                        if (string.IsNullOrEmpty(person.GetFieldValue <string>("FinancialAccountCode")))
                        {
                            person.SetFieldValue("FinancialAccountCode", GetNewFinancialAccountCode());
                            dbHelper.UpdateEntity(person);
                        }
                    }

                    tranManager.Commit();
                }
            }
        }
Example #20
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();
            }
        }
Example #21
0
        private void CreateOrUpdateReceiveReceiptAccDocItems(Entity receiveReceiptEntity, Guid accDocID)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            var receiveReceiptItemBL    = new ReceiveReceiptItemBL();
            var opFieldNameInItemEntity = "RefOp_ReceiveReceipt";

            var receiveReceiptID = receiveReceiptEntity.GetFieldValue <Guid>("ID");
            var financialYearID  = receiveReceiptEntity.GetFieldValue <Guid>("FinancialYear");

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

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                try
                {
                    acc.Instance.DeleteAccDocItems(accDocID, opFieldNameInItemEntity, receiveReceiptID);

                    var receiveReceiptItems = dbHelper.FetchMultiple("rp_ReceiveReceiptItemsView",
                                                                     string.Format("ReceiveReceipt = '{0}'", receiveReceiptID), null, null, null, null).Entities;

                    foreach (var receiveReceiptItem in receiveReceiptItems)
                    {
                        var personID = receiveReceiptItem.GetFieldValue <Guid>("Payer");
                        var desc     = receiveReceiptItem.GetFieldValue <string>("ItemDescription");

                        var debtorDesc   = receiveReceiptItem.GetFieldValue <string>("ItemDebtorDescription");
                        var creditorDesc = receiveReceiptItem.GetFieldValue <string>("ItemCreditorDescription");

                        var amount = receiveReceiptItem.GetFieldValue <decimal>("Amount");

                        Guid?creditorAccount = null;
                        Guid?debtorAccount   = null;

                        Guid?cashOwnerPerson = receiveReceiptItem.GetFieldValue <Guid?>("CashOwnerPerson");

                        Guid?creditor_CostCenter = receiveReceiptItem.GetFieldValue <Guid?>("Creditor_CostCenter");
                        Guid?creditor_Project    = receiveReceiptItem.GetFieldValue <Guid?>("Creditor_Project");

                        receiveReceiptItemBL.GetAccDocItemAccounts(receiveReceiptItem, out creditorAccount, out debtorAccount);

                        //بدهکار
                        var entity = new Entity();
                        entity.AddField("accountID", (Guid)debtorAccount);
                        entity.AddField("personID", cashOwnerPerson);
                        entity.AddField("costCenterID", null);
                        entity.AddField("projectID", null);
                        entity.AddField("foreignCurrencyID", null);
                        entity.AddField("note", debtorDesc);
                        entity.AddField("creditorAmount", 0);
                        entity.AddField("debtorAmount", amount);
                        entity.AddField("isActive", true);

                        accDocItemList.Add(entity);

                        //بستانکار
                        entity = new Entity();
                        entity.AddField("accountID", (Guid)creditorAccount);
                        entity.AddField("personID", personID);
                        entity.AddField("costCenterID", creditor_CostCenter);
                        entity.AddField("projectID", creditor_Project);
                        entity.AddField("foreignCurrencyID", null);
                        entity.AddField("note", creditorDesc);
                        entity.AddField("creditorAmount", amount);
                        entity.AddField("debtorAmount", 0);
                        entity.AddField("isActive", true);

                        accDocItemList.Add(entity);
                    }

                    acc.Instance.InsertAccDocItems(accDocID, opFieldNameInItemEntity, receiveReceiptID, accDocItemList);
                    tranManager.Commit();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Example #22
0
        public Entity ChangePaidChequesStatus(EntityList cheques, Entity statusChangeEntity)
        {
            //DebugHelper.Break();

            var resultEntity = new Entity();

            var dbHelper         = CoreComponent.Instance.MainDbHelper;
            var error            = "";
            var errorChequeIDs   = "";
            var succeedChequeIDs = "";

            var currentStatusText = dbHelper.FetchSingle("afw.OptionSetItem", string.Format("ID = '{0}'",
                                                                                            statusChangeEntity.GetFieldValue <Guid>("CurrentStatus")), null).GetFieldValue <string>("Title");
            var newStatusText = dbHelper.FetchSingle("afw.OptionSetItem", string.Format("ID = '{0}'",
                                                                                        statusChangeEntity.GetFieldValue <Guid>("NewStatus")), null).GetFieldValue <string>("Title");

            foreach (Entity chequeInfo in cheques.Entities)
            {
                using (var tranManager = new DbTransactionManager(dbHelper))
                {
                    var chequeID = chequeInfo.GetFieldValue <Guid>("ID");
                    var cheque   = dbHelper.FetchSingleByID("rp.PaidCheque", chequeID, null);

                    if (chequeInfo.GetFieldValue <DateTime?>("LastModifyTime") !=
                        cheque.GetFieldValue <DateTime?>("LastModifyTime"))
                    {
                        error += string.Format("خطا در تغییر وضعیت چک به شماره {0}: چک توسط کاربر دیگری تغییر یافته است. \r\n",
                                               chequeInfo.GetFieldValue <string>("ChequeNumber"));

                        if (errorChequeIDs != "")
                        {
                            errorChequeIDs += ",";
                        }
                        errorChequeIDs += chequeID.ToString();

                        continue;
                    }

                    try
                    {
                        var chequePersianDate = DateTimeHelper.GregorianDateTimeToPersianDate(cheque.GetFieldValue <DateTime>("DueDate"));
                        var newDesc           = string.Format("انتقال چک به شماره {0} مورخ {1} ",
                                                              cheque.GetFieldValue <string>("ChequeNumber"),
                                                              chequePersianDate);

                        var financialGroupID = chequeInfo.GetFieldValue <Guid?>("PayReceipt_FinancialGroup");
                        if (financialGroupID == null)
                        {
                            throw new AfwException("گروه مالی در عملیات پرداخت ثبت نشده است.");
                        }

                        new PaidChequeStatusChangeBL().CreateChequeStatusChange(chequeID,
                                                                                statusChangeEntity.GetFieldValue <Guid>("NewStatus"),
                                                                                statusChangeEntity.GetFieldValue <Guid>("FinancialYear"),
                                                                                (Guid)financialGroupID,
                                                                                statusChangeEntity.GetFieldValue <DateTime>("ChangeDate"),
                                                                                newDesc,
                                                                                true);

                        tranManager.Commit();

                        if (succeedChequeIDs != "")
                        {
                            succeedChequeIDs += ",";
                        }
                        succeedChequeIDs += chequeID.ToString();
                    }
                    catch (Exception ex)
                    {
                        error += string.Format("خطا در تغییر وضعیت چک به شماره {0}: {1}\r\n",
                                               chequeInfo.GetFieldValue <string>("ChequeNumber"), ex.Message);

                        if (errorChequeIDs != "")
                        {
                            errorChequeIDs += ",";
                        }
                        errorChequeIDs += chequeID.ToString();
                    }
                }
            }

            resultEntity.AddField("Error", error);
            resultEntity.AddField("SucceedChequeIDs", succeedChequeIDs);
            resultEntity.AddField("ErrorChequeIDs", errorChequeIDs);

            return(resultEntity);
        }
Example #23
0
        private void CreateTankhahAccDocItems(Entity tankhahEntity, Guid accDocID, bool repeatTotal)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            var opFieldNameInItemEntity = "RefOp_Tankhah";

            var tankhahID       = tankhahEntity.GetFieldValue <Guid>("ID");
            var financialYearID = tankhahEntity.GetFieldValue <Guid>("FinancialYear");

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                try
                {
                    acc.Instance.DeleteAccDocItems(accDocID, opFieldNameInItemEntity, tankhahID);
                    List <Entity> accDocItemList = new List <Entity>();

                    string queryString = "";

                    if (repeatTotal)
                    {
                        queryString = string.Format(@"
                            select Tankhah.ID, Tankhah.FinancialGroup, TankhahGardanAccSetting.Account TankhahGardanAccount, TankhahItem.Amount, 
                                TankhahItem.TankhahDefAccount, TankhahItem.Description ItemDes, TankhahItem.TankhahTypeName, Tankhah.Person, 
                                TankhahItem.ItemPerson, TankhahItem.ItemCostCenter, TankhahItem.ItemProject, Tankhah.Description KolDes
                            from rp_Tankhahha Tankhah
                                inner join rp_TankhahGardanha TankhahGardan on TankhahGardan.ID = Tankhah.TankhahGardan
	                            left join rp_TankhahGardanAccSettings TankhahGardanAccSetting 
		                            on TankhahGardanAccSetting.TankhahGardan = TankhahGardan.ID
                                inner join (
                                    select TankhahItem.Tankhah, TankhahItem.Amount, TarafHesabeTankhahAccSetting.Account TankhahDefAccount, 
                                        TankhahType.Name TankhahTypeName, FloatPriority.Account FloatPriorityAccount, TankhahItem.Description,
                                        TankhahItem.Person ItemPerson, TankhahItem.CostCenter ItemCostCenter, TankhahItem.Project ItemProject 
                                    from rp_TankhahItems TankhahItem
                                        inner join rp_TankhahDefs TankhahDef on TankhahDef.ID = TankhahItem.TankhahDef
			                            left join rp_TarafHesabeTankhahAccSettings TarafHesabeTankhahAccSetting 
				                            on TarafHesabeTankhahAccSetting.TarafHesabeTankhah = TankhahDef.ID
                                        inner join afw_OptionSetItems TankhahType on TankhahType.ID = TankhahItem.TankhahType
                                        left join cmn_FloatPriorities FloatPriority on FloatPriority.Account = TarafHesabeTankhahAccSetting.Account
                                    where FloatPriority.Account is not null 
                                    union 
                                    select TankhahItem.Tankhah, sum(TankhahItem.Amount) Amount, TarafHesabeTankhahAccSetting.Account TankhahDefAccount,
                                        TankhahType.Name TankhahTypeName, FloatPriority.Account FloatPriorityAccount, TankhahItem.Description,
                                        null ItemPerson, null ItemCostCenter, null ItemProject 
                                    from rp_TankhahItems TankhahItem
                                        inner join rp_TankhahDefs TankhahDef on TankhahDef.ID = TankhahItem.TankhahDef
			                            left join rp_TarafHesabeTankhahAccSettings TarafHesabeTankhahAccSetting 
				                            on TarafHesabeTankhahAccSetting.TarafHesabeTankhah = TankhahDef.ID
                                        inner join afw_OptionSetItems TankhahType on TankhahType.ID = TankhahItem.TankhahType
                                        left join cmn_FloatPriorities FloatPriority on FloatPriority.Account = TarafHesabeTankhahAccSetting.Account
                                    where FloatPriority.Account is null 
                                    group by TankhahItem.Tankhah, TarafHesabeTankhahAccSetting.Account, TankhahType.Name, FloatPriority.Account, TankhahItem.Description
                                    ) TankhahItem on TankhahItem.Tankhah = Tankhah.ID
                            where Tankhah.ID = '{0}' 
                                and Tankhah.FinancialYear = '{1}' 
                                and TarafHesabeTankhahAccSetting.FinancialYear = '{1}'
                                and TankhahGardanAccSetting.FinancialYear = '{1}'",
                                                    tankhahID, financialYearID);
                    }
                    else
                    {
                        queryString = string.Format(@"
                            select  Tankhah.ID, Tankhah.FinancialGroup, TankhahGardanAccSetting.Account TankhahGardanAccount, isnull(TankhahItem.Amount, 0) Amount, 
	                            TarafHesabeTankhahAccSetting.Account TankhahDefAccount, TankhahItem.Description ItemDes, TankhahType.Name TankhahTypeName, Tankhah.Person, 
	                            TankhahItem.Person ItemPerson, TankhahItem.CostCenter ItemCostCenter, TankhahItem.Project ItemProject, Tankhah.Description KolDes
                            from rp_Tankhahha Tankhah
	                            left join rp_TankhahItems TankhahItem on TankhahItem.Tankhah = Tankhah.ID
	                            left join rp_TankhahGardanha TankhahGardan on TankhahGardan.ID = Tankhah.TankhahGardan
	                            left join rp_TankhahGardanAccSettings TankhahGardanAccSetting 
		                            on TankhahGardanAccSetting.TankhahGardan = TankhahGardan.ID
	                            inner join rp_TankhahDefs TankhahDef on TankhahDef.ID = TankhahItem.TankhahDef
	                            left join rp_TarafHesabeTankhahAccSettings TarafHesabeTankhahAccSetting 
		                            on TarafHesabeTankhahAccSetting.TarafHesabeTankhah = TankhahDef.ID
	                            left join afw_OptionSetItems TankhahType on TankhahType.ID = TankhahItem.TankhahType 
						    where Tankhah.ID = '{0}' 
                                and Tankhah.FinancialYear = '{1}' 
                                and TarafHesabeTankhahAccSetting.FinancialYear = '{1}'
                                and TankhahGardanAccSetting.FinancialYear = '{1}'",
                                                    tankhahID, financialYearID);
                    }

                    var entityItemsList = dbHelper.FetchMultipleBySqlQuery(queryString).Entities;

                    if (entityItemsList.Count < 1)
                    {
                        throw new AfwException("برای تنخواه انتخاب شده سطری یافت نشد.");
                    }

                    Guid?   accountMasterSide        = null;
                    decimal debtorAmountMasterSide   = 0;
                    decimal creditorAmountMasterSide = 0;
                    accountMasterSide = entityItemsList[0].GetFieldValue <Guid>("TankhahGardanAccount");
                    var personID = entityItemsList[0].GetFieldValue <Guid>("Person");
                    var kolDes   = entityItemsList[0].GetFieldValue <string>("KolDes");

                    foreach (var entityItem in entityItemsList)
                    {
                        var itemPersonID     = entityItem.GetFieldValue <Guid?>("ItemPerson");
                        var itemCostCenterID = entityItem.GetFieldValue <Guid?>("ItemCostCenter");
                        var itemProjectID    = entityItem.GetFieldValue <Guid?>("ItemProject");
                        var amount           = entityItem.GetFieldValue <decimal>("Amount");
                        var itemDes          = entityItem.GetFieldValue <string>("ItemDes");

                        var accountDetailSide = entityItem.GetFieldValue <Guid>("TankhahDefAccount");

                        /*آیتم های بدهکار************************/
                        if (entityItem.GetFieldValue <string>("TankhahTypeName") == "Paid")
                        {
                            creditorAmountMasterSide += entityItem.GetFieldValue <decimal>("Amount");

                            var entity = new Entity();
                            entity.AddField("accountID", (Guid)accountDetailSide);
                            entity.AddField("personID", itemPersonID);
                            entity.AddField("costCenterID", itemCostCenterID);
                            entity.AddField("projectID", itemProjectID);
                            entity.AddField("foreignCurrencyID", null);
                            entity.AddField("note", itemDes);
                            entity.AddField("creditorAmount", 0);
                            entity.AddField("debtorAmount", amount);
                            entity.AddField("isActive", true);

                            accDocItemList.Add(entity);
                        }

                        /*آیتم های بستانکار*******************************/
                        if (entityItem.GetFieldValue <string>("TankhahTypeName") == "Received")
                        {
                            debtorAmountMasterSide += entityItem.GetFieldValue <decimal>("Amount");

                            var entity = new Entity();
                            entity.AddField("accountID", (Guid)accountDetailSide);
                            entity.AddField("personID", itemPersonID);
                            entity.AddField("costCenterID", itemCostCenterID);
                            entity.AddField("projectID", itemProjectID);
                            entity.AddField("foreignCurrencyID", null);
                            entity.AddField("note", itemDes);
                            entity.AddField("creditorAmount", amount);
                            entity.AddField("debtorAmount", 0);
                            entity.AddField("isActive", true);

                            accDocItemList.Add(entity);
                        }
                    }

                    /*مجموع بدهکار************************/
                    if (debtorAmountMasterSide > 0)
                    {
                        var entity = new Entity();
                        entity.AddField("accountID", (Guid)accountMasterSide);
                        entity.AddField("personID", personID);
                        entity.AddField("costCenterID", null);
                        entity.AddField("projectID", null);
                        entity.AddField("foreignCurrencyID", null);
                        entity.AddField("note", kolDes);
                        entity.AddField("creditorAmount", 0);
                        entity.AddField("debtorAmount", debtorAmountMasterSide);
                        entity.AddField("isActive", true);

                        accDocItemList.Add(entity);
                    }
                    /*مجموع بستانکار*******************************/
                    if (creditorAmountMasterSide > 0)
                    {
                        var entity = new Entity();
                        entity.AddField("accountID", (Guid)accountMasterSide);
                        entity.AddField("personID", personID);
                        entity.AddField("costCenterID", null);
                        entity.AddField("projectID", null);
                        entity.AddField("foreignCurrencyID", null);
                        entity.AddField("note", kolDes);
                        entity.AddField("creditorAmount", creditorAmountMasterSide);
                        entity.AddField("debtorAmount", 0);
                        entity.AddField("isActive", true);

                        accDocItemList.Add(entity);
                    }

                    acc.Instance.InsertAccDocItems(accDocID, opFieldNameInItemEntity, tankhahID, accDocItemList);
                    tranManager.Commit();
                }
                catch (Exception ex)
                {
                    throw new AfwException(ex.Message);
                }
            }
        }
Example #24
0
        public void SaveQuickSettelmentEntity(Entity receiveReceiptEntity, Entity fileSettlementEntity, bool isWorkShift)
        {
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            var organizationUnitID = receiveReceiptEntity.GetFieldValue <Guid>("OrganizationUnit");

            if (receiveReceiptEntity.ChangeStatus == EntityChangeTypes.Delete)
            {
                throw new AfwException("receiveReceiptEntity is in Deleted status.");
            }

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

                try
                {
                    if (receiveReceiptEntity.FieldExists("Items"))
                    {
                        var     itemsEntityList = receiveReceiptEntity.GetFieldValue <EntityList>("Items");
                        decimal totalAmount     = 0;

                        foreach (Entity itemEntity in itemsEntityList.Entities)
                        {
                            var innerItem  = itemEntity.GetFieldValue <Entity>("InnerItem");
                            var itemAmount = innerItem.GetFieldValue <decimal?>("Amount");

                            if (innerItem.FieldExists("ShomareHavale"))
                            {
                                var lastShomareHavale = cmn.Instance.GetFieldMaxIntValue("ShomareHavale", "rp_HavaleDaryafti",
                                                                                         string.Format(@"ID in (
                                        select FinancialItem_Havale  
                                        from rp_ReceiveReceiptItems  
                                        where ReceiveReceipt = '{0}' and FinancialItem_Havale is not null)",
                                                                                                       receiveReceiptEntity.GetFieldValue <Guid>("ID")));

                                if (lastShomareHavale == 0)
                                {
                                    lastShomareHavale = Convert.ToInt32(receiveReceiptEntity.GetFieldValue <Int64>("ReceiptNumber").ToString() + "100");
                                }
                                else
                                {
                                    lastShomareHavale++;
                                }

                                innerItem.SetFieldValue("ShomareHavale", lastShomareHavale);
                            }

                            if (isWorkShift)
                            {
                                var openedWorkShift = dbHelper.FetchSingle("krf.WorkShift",
                                                                           string.Format("IsOpen = 1 and OrganizationUnit = '{0}'", organizationUnitID), null);

                                if (openedWorkShift != null)
                                {
                                    var workShiftStatusChange = dbHelper.FetchSingle("krf.WorkShiftStatusChange",
                                                                                     string.Format("WorkShift = '{0}' and CloseDateTime is null",
                                                                                                   openedWorkShift.GetFieldValue <Guid>("ID")), null);

                                    itemEntity.SetFieldValue("Krf_WorkShiftStatusChange", workShiftStatusChange.GetFieldValue <Guid>("ID"));
                                    itemEntity.SetFieldValue("Debtor_Project", openedWorkShift.GetFieldValue <Guid>("Project"));
                                }
                            }

                            if (itemAmount == null || itemAmount == 0)
                            {
                                itemEntity.ChangeStatus = EntityChangeTypes.None;
                            }
                            else
                            {
                                totalAmount += (decimal)itemAmount;
                            }
                        }

                        dbHelper.ApplyChanges(itemsEntityList);

                        if (fileSettlementEntity != null)
                        {
                            if (fileSettlementEntity.FieldExists("TotalAmount"))
                            {
                                if (fileSettlementEntity.ChangeStatus == EntityChangeTypes.Add)
                                {
                                    fileSettlementEntity.SetFieldValue("FirstAmount", totalAmount);
                                }
                                fileSettlementEntity.SetFieldValue("TotalAmount", totalAmount);
                            }

                            dbHelper.ApplyChanges(fileSettlementEntity);
                        }
                    }

                    tranManager.Commit();
                }
                catch (Exception ex)
                {
                    throw new AfwException("خطا در ثبت..\r\n {0}", ex.Message);
                }
            }
        }
Example #25
0
        public void SavePerson(Entity person)
        {
            //DebugHelper.Break();

            var dbHelper = CoreComponent.Instance.MainDbHelper;

            var personID = person.GetFieldValue <Guid>("ID");

            EntityList personRoleRelations = new EntityList();

            if (person.FieldExists("PersonRoleRelations"))
            {
                personRoleRelations = person.GetFieldValue <EntityList>("PersonRoleRelations");
            }

            EntityList personGroupRelations = null;

            if (person.FieldExists("PersonGroupRelations"))
            {
                personGroupRelations = person.GetFieldValue <EntityList>("PersonGroupRelations");
            }

            CheckRoleRelations(person);

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                var roleInfoEntities = new List <Entity>();

                foreach (var role in GetPersonRoles())
                {
                    var roleName = role.GetFieldValue <string>("Name");
                    if (person.FieldExists(roleName + "Info"))
                    {
                        var roleInfoEntity = person.GetFieldValue <Entity>(roleName + "Info");
                        if (roleInfoEntity.GetFieldValue <string>("PersonCode") == null)
                        {
                            roleInfoEntity.SetFieldValue("PersonCode", GetNewPersonCode(roleName));
                        }
                        roleInfoEntities.Add(roleInfoEntity);

                        if (role.GetFieldValue <bool>("HasFinancialAccount") &&
                            string.IsNullOrEmpty(person.GetFieldValue <string>("FinancialAccountCode")))
                        {
                            person.SetFieldValue("FinancialAccountCode", GetNewFinancialAccountCode());
                        }

                        person.FieldValues.Remove(roleName + "Info");
                    }
                }

                dbHelper.ApplyChanges(person);

                foreach (Entity personRoleRelationEntity in personRoleRelations.Entities)
                {
                    dbHelper.ApplyChanges(personRoleRelationEntity);
                }

                foreach (var roleInfoEntity in roleInfoEntities)
                {
                    dbHelper.ApplyChanges(roleInfoEntity);
                }

                if (personGroupRelations != null)
                {
                    foreach (Entity personGroupRelationEntity in personGroupRelations.Entities)
                    {
                        dbHelper.ApplyChanges(personGroupRelationEntity);
                    }
                }

                if (PersonHasRole(personID, "PotentialCustomer") && PersonHasRole(personID, "Customer"))
                {
                    SetPotentialCustomerGroupingToCustomer(personID);
                    DeletePotentialCustomerRole(person);
                }

                tranManager.Commit();
            }
        }
Example #26
0
        public void SaveSalesCase(Entity salesCase)
        {
            //DebugHelper.Break();

            var core     = CoreComponent.Instance;
            var dbHelper = CoreComponent.Instance.MainDbHelper;

            using (var tranManager = new DbTransactionManager(dbHelper))
            {
                if (salesCase.FieldExists("SalesCaseLoseInfo") &&
                    salesCase.ChangeStatus == EntityChangeTypes.Modify)
                {
                    var salesCaseLoseInfo = salesCase.GetFieldValue <Entity>("SalesCaseLoseInfo");
                    salesCaseLoseInfo.ChangeStatus = EntityChangeTypes.Modify;
                    dbHelper.ApplyChanges(salesCaseLoseInfo);
                    salesCase.FieldValues.Remove("SalesCaseLoseInfo");
                }

                salesCase.FieldValues["LastActionTime"] = core.GetServerDateTime();

                if (salesCase.ChangeStatus == EntityChangeTypes.Modify)
                {
                    var oldSaleCaseEntity = dbHelper.FetchSingle("crm.SalesCase", string.Format("ID = '{0}'", salesCase.GetFieldValue <Guid>("ID")), null);

                    if (oldSaleCaseEntity.GetFieldValue <Guid?>("SalesCaseStage") != salesCase.GetFieldValue <Guid?>("SalesCaseStage"))
                    {
                        SaveSalesCaseStageChangeHistory(salesCase);
                    }
                    if (oldSaleCaseEntity.GetFieldValue <Guid?>("OwnerUser") != salesCase.GetFieldValue <Guid?>("OwnerUser"))
                    {
                        SaveSalesCaseOwnerUserChangeHistory(salesCase);
                    }
                    if (oldSaleCaseEntity.GetFieldValue <Guid?>("Status") != salesCase.GetFieldValue <Guid?>("Status"))
                    {
                        SaveSalesCaseStatusChangeHistory(salesCase);
                    }

                    dbHelper.ApplyChanges(salesCase);
                }
                else if (salesCase.ChangeStatus == EntityChangeTypes.Add)
                {
                    dbHelper.ApplyChanges(salesCase);

                    SaveSalesCaseStageChangeHistory(salesCase);
                    SaveSalesCaseOwnerUserChangeHistory(salesCase);
                    SaveSalesCaseStatusChangeHistory(salesCase);
                }
                else
                {
                    throw new AfwException("Invalid ChangeStatus for SaveSalesCase.");
                }

                SetCustomerRole(salesCase);

                if (salesCase.GetFieldValue <Guid?>("MainConnectedPerson") != null)
                {
                    SetMainConnectedPersonRole(salesCase);
                    AddMainConnectedPersonToConnectedPersonsIfNot(salesCase);
                }

                if (salesCase.GetFieldValue <Guid?>("IntroducerPerson") != null)
                {
                    SetIntroducerPersonRole(salesCase);
                }

                tranManager.Commit();
            }
        }