public override string OnApproveWaitApprove(long workFlowID, object eventData)
        {
            /*TODO validate , save event data to workflow*/
            WorkFlow    workFlow    = WorkFlowQueryProvider.WorkFlowQuery.FindByIdentity(workFlowID);
            SCGDocument scgDocument = ScgeAccountingQueryProvider.SCGDocumentQuery.GetSCGDocumentByDocumentID(workFlow.Document.DocumentID);

            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
            MPADocument mpaDocument = ScgeAccountingQueryProvider.MPADocumentQuery.GetMPADocumentByDocumentID(workFlow.Document.DocumentID);

            if (!errors.IsEmpty)
            {
                throw new SS.Standard.Utilities.ServiceValidationException(errors);
            }

            try
            {
                ////SubmitResponse submitResponse = eventData as SubmitResponse;
                WorkFlowResponse response = new WorkFlowResponse();
                int workFlowStateEventId;
                response.WorkFlow = workFlow;

                response.ResponseBy   = UserAccount.UserID;
                response.ResponseDate = DateTime.Now;

                response.Active  = true;
                response.CreBy   = UserAccount.UserID;
                response.CreDate = DateTime.Now;
                response.UpdBy   = UserAccount.UserID;
                response.UpdDate = DateTime.Now;
                response.UpdPgm  = UserAccount.CurrentProgramCode;


                if (eventData is RejectDetailResponse)
                {
                    RejectDetailResponse rejectDetailResponse = eventData as RejectDetailResponse;
                    workFlowStateEventId = rejectDetailResponse.WorkFlowStateEventID;
                    WorkFlowRejectResponse rejectResponse = new WorkFlowRejectResponse();
                    rejectResponse.WorkFlowResponse = response;
                    if (rejectDetailResponse.ReasonID != 0)
                    {
                        rejectResponse.Reason = ScgDbQueryProvider.DbRejectReasonQuery.FindProxyByIdentity(rejectDetailResponse.ReasonID);
                    }
                    rejectResponse.Remark  = rejectDetailResponse.Remark;
                    rejectResponse.Active  = true;
                    rejectResponse.CreBy   = UserAccount.UserID;
                    rejectResponse.CreDate = DateTime.Now;
                    rejectResponse.UpdBy   = UserAccount.UserID;
                    rejectResponse.UpdDate = DateTime.Now;
                    rejectResponse.UpdPgm  = UserAccount.CurrentProgramCode;

                    if (rejectDetailResponse.ResponseMethod != null)
                    {
                        response.ResponseMethod = rejectDetailResponse.ResponseMethod.GetHashCode().ToString();
                    }
                    response.WorkFlowStateEvent = WorkFlowQueryProvider.WorkFlowStateEventQuery.FindByIdentity(workFlowStateEventId);
                    WorkFlowDaoProvider.WorkFlowResponseDao.Save(response);

                    if (rejectDetailResponse.ReasonID != 0 || !string.IsNullOrEmpty(rejectDetailResponse.Remark))
                    {
                        WorkFlowDaoProvider.WorkFlowRejectResponseDao.Save(rejectResponse);
                    }
                }
                else
                {
                    SubmitResponse submitResponse = eventData as SubmitResponse;
                    workFlowStateEventId = submitResponse.WorkFlowStateEventID;
                    if (submitResponse.ResponseMethod != null)
                    {
                        response.ResponseMethod = submitResponse.ResponseMethod.GetHashCode().ToString();
                    }

                    response.WorkFlowStateEvent = WorkFlowQueryProvider.WorkFlowStateEventQuery.FindByIdentity(workFlowStateEventId);
                    WorkFlowDaoProvider.WorkFlowResponseDao.Save(response);
                }
                scgDocument.ApproveDate = DateTime.Now;
                scgDocument.UpdBy       = UserAccount.UserID;
                scgDocument.UpdDate     = DateTime.Now;
                scgDocument.UpdPgm      = UserAccount.CurrentProgramCode;
                SCGDocumentService.SaveOrUpdate(scgDocument);

                if (ParameterServices.EnableEmail02Creator || ParameterServices.EnableEmail02Requester || ParameterServices.EnableEmail02Initiator)
                {
                    long         sendToUserID = 0;
                    IList <long> ccList       = new List <long>();

                    if (ParameterServices.EnableEmail02Creator)
                    {
                        sendToUserID = scgDocument.CreatorID.Userid;
                    }

                    if (ParameterServices.EnableEmail02Requester)
                    {
                        if (sendToUserID == 0)
                        {
                            sendToUserID = scgDocument.RequesterID.Userid;
                        }
                        else if (scgDocument.CreatorID.Userid != scgDocument.RequesterID.Userid)
                        {
                            ccList.Add(scgDocument.RequesterID.Userid);
                        }

                        //Send mail02 to all travellers that doesnot requester
                        IList <MPAItem> items = ScgeAccountingQueryProvider.MPAItemQuery.FindMPAItemByMPADocumentID(mpaDocument.MPADocumentID);
                        foreach (MPAItem item in items)
                        {
                            if (sendToUserID == 0)
                            {
                                sendToUserID = item.UserID.Userid;
                            }
                            else if (item.UserID.Userid != sendToUserID && !ccList.Contains(item.UserID.Userid))
                            {
                                ccList.Add(item.UserID.Userid);
                            }
                        }
                    }
                    if (ParameterServices.EnableEmail02Initiator)
                    {
                        IList <DocumentInitiator> initiators = ScgeAccountingQueryProvider.DocumentInitiatorQuery.GetDocumentInitiatorByDocumentID(workFlow.Document.DocumentID);
                        foreach (DocumentInitiator initiator in initiators)
                        {
                            if (sendToUserID == 0)
                            {
                                sendToUserID = initiator.UserID.Userid;
                            }
                            else if (initiator.UserID.Userid != sendToUserID && !ccList.Contains(initiator.UserID.Userid))
                            {
                                ccList.Add(initiator.UserID.Userid);
                            }
                        }
                    }

                    SCGEmailService.SendEmailEM02(response.WorkFlowResponseID, sendToUserID, ccList);
                }
            }
            catch (Exception)
            {
                throw;
            }


            // ====================== For Approve all advance that link to TA ======================
            // Use state WaitApprove to add into table WorkflowResponse
            string             eventName  = "Approve";
            WorkFlowStateEvent stateEvent = WorkFlowQueryProvider.WorkFlowStateEventQuery.GetByWorkFlowStateID_EventName(AdvanceStateID.WaitApprove, eventName);

            return("ApproveWaitApproveToComplete");
        }
Пример #2
0
        public long Save()
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

            CADocumentDataSet caDocumentDS = (CADocumentDataSet)TransactionService.GetDS(this.TransactionID);

            if (caDocumentDS == null)
            {
                OnDsNull();
            }
            CADocumentDataSet.CADocumentRow caDocumentRow = caDocumentDS.CADocument.FindByCADocumentID(this.CADocumentID);
            long tempDocumentID = caDocumentRow.DocumentID;

            #region SCGDocument
            SCGDocument scgDocument = new SCGDocument(tempDocumentID);
            if (!string.IsNullOrEmpty(ctlCompanyField.CompanyID))
            {
                scgDocument.CompanyID = new DbCompany(UIHelper.ParseLong(ctlCompanyField.CompanyID));
            }
            scgDocument.CreatorID = new SuUser(UIHelper.ParseLong(ctlCreatorData.UserID));
            if (!string.IsNullOrEmpty(ctlRequesterData.UserID))
            {
                scgDocument.RequesterID = new SuUser(UIHelper.ParseLong(ctlRequesterData.UserID));
            }
            scgDocument.Subject = ctlSubject.Text;
            if (!string.IsNullOrEmpty(ctlApproverData.UserID))
            {
                scgDocument.ApproverID = new SuUser(UIHelper.ParseLong(ctlApproverData.UserID));
            }

            scgDocument.DocumentType = new SS.Standard.WorkFlow.DTO.DocumentType(DocumentTypeID.CADocument);


            scgDocument.Memo   = ctlMemo.Text;
            scgDocument.Active = true;

            try
            {
                // Save SCG Document to Transaction.
                SCGDocumentService.UpdateTransactionDocument(this.TransactionID, scgDocument, false, true);
            }
            catch (ServiceValidationException ex)
            {
                errors.MergeErrors(ex.ValidationErrors);
            }
            #endregion SCGDocument

            #region CADocument
            CADocument caDocument = new CADocument(this.CADocumentID);

            caDocument.DocumentID = scgDocument;

            if (ctlSomeTime.Checked)
            {
                caDocument.IsTemporary = true;
                try
                {
                    if (ctlStartDateSumtime.Value != null)
                    {
                        caDocument.StartDate = ctlStartDateSumtime.Value.Value;
                    }

                    if (ctlEndDateSumtime.Value != null)
                    {
                        caDocument.EndDate = ctlEndDateSumtime.Value.Value;
                    }
                }
                catch (FormatException fex)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Invalid_Date_Format"));
                    throw new ServiceValidationException(errors);
                }
            }
            else if (ctlRegular.Checked)
            {
                caDocument.IsTemporary = false;
                try
                {
                    if (ctlStartDate.Value != null)
                    {
                        caDocument.StartDate = ctlStartDate.Value.Value;
                    }

                    if (ctlEndDate.Value != null)
                    {
                        caDocument.EndDate = ctlEndDate.Value.Value;
                    }
                }
                catch (FormatException fex)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Invalid_Date_Format"));
                    throw new ServiceValidationException(errors);
                }
            }

            caDocument.CarLicenseNo = ctlCarLicenseNo.Text;
            caDocument.Brand        = ctlBrand.Text;
            caDocument.Model        = ctlModel.Text;

            switch (ctlDropDownListCategory.SelectedValue)
            {
            case "1":
                caDocument.OwnerType = OwnerMileage.Employee;
                break;

            case "2":
                caDocument.OwnerType = OwnerMileage.Company;
                break;

            default:
                break;
            }

            switch (ctlDropDownListType.SelectedValue)
            {
            case "1":
                caDocument.CarType = TypeOfCar.PrivateCar;
                break;

            case "2":
                caDocument.CarType = TypeOfCar.MotorCycle;
                break;

            case "3":
                caDocument.CarType = TypeOfCar.Pickup;
                break;

            default:
                break;
            }

            if (caDocument.IsTemporary)
            {
                if (ctlWorkInArea.Checked || ctlWorkOutOfArea.Checked)
                {
                    if (ctlWorkInArea.Checked)
                    {
                        caDocument.IsWorkArea = true;
                    }
                    else if (ctlWorkOutOfArea.Checked)
                    {
                        caDocument.IsWorkArea = false;
                        caDocument.Remark     = ctlWorkOutOfAreatxt.Text;
                    }
                }
                else
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Please Select Work Area."));
                }
            }
            else
            {
                if (ctlWorkInArea.Checked)
                {
                    caDocument.IsWorkArea = true;
                }
                else if (ctlWorkOutOfArea.Checked)
                {
                    caDocument.IsWorkArea = false;
                    caDocument.Remark     = ctlWorkOutOfAreatxt.Text;
                }
            }

            caDocument.Active = true;

            try
            {
                // Get ta document information and save to transaction.
                CADocumentService.UpdateCADocumentTransaction(this.TransactionID, caDocument);
            }
            catch (ServiceValidationException ex)
            {
                errors.MergeErrors(ex.ValidationErrors);
            }

            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }

            #endregion CADocument

            try
            {
                ctlInitiator.Save();
                DocumentInitiatorService.ValidateDocumentInitiator(this.TransactionID, this.CADocumentID);
            }
            catch (ServiceValidationException ex)
            {
                errors.MergeErrors(ex.ValidationErrors);
            }

            if (!errors.IsEmpty)
            {
                // If have some validation error then return error.
                throw new ServiceValidationException(errors);
            }
            else
            {
                return(this.SaveToDatabase());
            }
        }
Пример #3
0
        public bool ApprovePosting(long DocID, DocumentKind DocKind)
        {
            try
            {
                bool        isSuccess   = true;
                bool        ChangeState = false;
                SCGDocument doc         = ScgeAccountingQueryProvider.SCGDocumentQuery.GetSCGDocumentByDocumentID(DocID);

                if (doc == null)
                {
                }
                else if (!CanApprove(DocID, DocKind.ToString()))
                {
                }
                else if (this.GetPostingService(DocKind.ToString()).GetDocumentStatus(DocID, DocKind.ToString()) == "A")
                {
                }
                else
                {
                    #region Approve
                    IList <BAPIApproveReturn> bapiReturn = this.GetPostingService(DocKind.ToString()).BAPIApprove(DocID, DocKind.ToString(), this.UserAccount.UserID);

                    if (DocKind.ToString() == DocumentKind.ExpenseRemittance.ToString())
                    {
                        FnExpenseDocument docExpense = ScgeAccountingQueryProvider.FnExpenseDocumentQuery.GetExpenseDocumentByDocumentID(DocID);
                        if (GetPostingService(DocKind.ToString()).GetDocumentStatus(DocID, DocKind.ToString()) == "A")
                        {
                            docExpense.RemittancePostingStatus = "C";
                            FnExpenseDocumentService.SaveOrUpdate(docExpense);
                        }
                        else if (GetPostingService(DocKind.ToString()).GetDocumentStatus(DocID, DocKind.ToString()) == "PP")
                        {
                            docExpense.RemittancePostingStatus = "PP";
                            FnExpenseDocumentService.SaveOrUpdate(docExpense);
                        }
                    }
                    else
                    {
                        if (this.GetPostingService(DocKind.ToString()).GetDocumentStatus(DocID, DocKind.ToString()) == "A")
                        {
                            doc.PostingStatus = "C";
                            SCGDocumentService.SaveOrUpdate(doc);
                        }
                        else if (this.GetPostingService(DocKind.ToString()).GetDocumentStatus(DocID, DocKind.ToString()) == "PP")
                        {
                            doc.PostingStatus = "PP";
                            SCGDocumentService.SaveOrUpdate(doc);
                        }
                    }
                    #endregion Approve

                    #region Call WorkFlow
                    for (int i = 0; i < bapiReturn.Count; i++)
                    {
                        if (bapiReturn[i].ApproveStatus != "S")
                        {
                            isSuccess = false;
                            break;
                        }
                    }
                    if (isSuccess)
                    {
                        ChangeState = true;
                        WorkFlowApprove(DocKind.ToString());
                    }
                    #endregion Call WorkFlow

                    if (ChangeState)
                    {
                        string wfid = System.Web.HttpContext.Current.Request.QueryString["wfid"].ToString();
                        System.Web.HttpContext.Current.Response.Redirect("SubmitResult.aspx?wfid=" + wfid);
                    }
                }
                return(isSuccess);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }