Example #1
0
        private static Schedule EvaluateScheduleWorkFlow(Schedule s)
        {
            // Lock this schedule for now
            s.processing = true;
            SaveSchedule(s);

            string[] passedStates = { Constants.WF_VALIDATION_PASSED, Constants.WF_STATUS_PASSED_NEW_EMPLOYEE };

            if (passedStates.Contains(s.validation_status))
            {
                EvaluatePassedSchedule(s);
            }
            else
            {
                //  Is the Schedule Validated?
                s.validated = CheckValidation(s.company_id, s.tier, s.contributiontypeid, s.month, s.year);
                
                if (s.validated)
                {
                    s.amount = (decimal) GetTotalContribution(s.company_id, s.tier, s.contributiontypeid, s.month, s.year);

                    s.validation_valuetime = CheckValidationTime(s.company_id, s.tier, s.contributiontypeid, s.month, s.year);

                    s.validation_status = CheckValidationStatus(s.company_id, s.tier, s.contributiontypeid, s.month, s.year);

                    //  Has Schedule has now passed?
                    if (passedStates.Contains(s.validation_status))
                    {
                        // Yes
                        s.workflow_status = Constants.WF_STATUS_PAYMENTS_PENDING;
                        s.workflow_summary = "Schedule has been validated with no errors. Waiting for payments.";
                        
                        // Expire any pending validation requestions
                        ExpireByJob(Constants.NF_TYPE_SCHEDULE_VALIDATION_REQUEST, Constants.JOB_TYPE_SCHEDULE, s.id);
                        ExpireByJob(Constants.NF_TYPE_SCHEDULE_ERRORFIX_REQUEST, Constants.JOB_TYPE_SCHEDULE, s.id);
                        ExpireByJob(Constants.NF_TYPE_SCHEDULE_ERRORFIX_ESCALATION_REQUEST, Constants.JOB_TYPE_SCHEDULE, s.id);
                        
                        EvaluatePassedSchedule(s);
                    }
                    else
                    {
                        // No
                        s.workflow_status = Constants.WF_STATUS_ERROR_PREFIX + s.validation_status;
                        EvaluateReminderStatus(s);  
                    }
                }
                else
                {
                    // send reminders
                    int times_sent = UpdateNotificationStatus(s.id, Constants.NF_TYPE_SCHEDULE_VALIDATION_REQUEST, Constants.SETTINGS_TIME_INTERVAL_VALIDATION_REQUEST);
                    s.workflow_status = Constants.WF_VALIDATION_NOTDONE_REMINDER;
                    s.workflow_summary = string.Format("Schedule is not validated. {0} notification request sent.",times_sent);
                    s.processing = false;
                    SaveSchedule(s);
                }
            }

            return s;
        }
Example #2
0
 partial void DeleteSchedule(Schedule instance);
Example #3
0
 partial void UpdateSchedule(Schedule instance);
Example #4
0
 partial void InsertSchedule(Schedule instance);
Example #5
0
		private void detach_Schedules(Schedule entity)
		{
			this.SendPropertyChanging();
			entity.PPayment = null;
		}
Example #6
0
		private void attach_Schedules(Schedule entity)
		{
			this.SendPropertyChanging();
			entity.PPayment = this;
		}
Example #7
0
 private static Schedule SaveSchedule(Schedule s)
 {
     s.modified_by = _defaultUserId;
     s.updated_at = DateTime.Now;
     Database.Tracker.SubmitChanges();
     return s;
 }
Example #8
0
        private static Schedule EvaluateFileUploadNotificationStatus(Schedule s)
        {
            bool fileuploaded = false;
            try
            {
                fileuploaded = CheckFileUploaded(s.company, s.company_id, s.tier, s.PPayment.value_date, s.PPayment.transaction_amount);
            }
            catch(Exception)
            {
            }

            if (fileuploaded)
            {
                 s.file_uploaded = true;
                 s.file_uploaded_date = DateTime.Now;
                               
                if (s.receipt_sent)
                {
                    s.workflow_status = Constants.WF_STATUS_COMPLETED;
                    s.workflow_summary = string.Format("Receipt sent {0} and File downloaded {1} and File uploaded {2}", s.receipt_sent_date.ToString(), s.file_downloaded_date.ToString(), s.file_uploaded_date.ToString());
                }
                else
                {
                    s.workflow_status = Constants.WF_STATUS_RF_NOSENT_DOWNLOAD_UPLOAD;
                    s.workflow_summary = string.Format("No Receipt sent. File downloaded {0} and File uploaded {1}", s.file_downloaded_date.ToString(), s.file_uploaded_date.ToString());
                }

                // Resolve old notifications
                ResolveByJob(Constants.NF_TYPE_SCHEDULE_FILE_UPLOAD_REQUEST, Constants.JOB_TYPE_SCHEDULE, s.id);
            }
            else
            {
                if (FileUploadWindowHasExpired((DateTime)s.file_downloaded_date))
                {

                    s.file_downloaded = false;
                    s.file_downloaded_date = null;

                    if (s.receipt_sent)
                    {
                        s.workflow_status = Constants.WF_STATUS_RF_SENT_NODOWNLOAD_NOUPLOAD;
                        s.workflow_summary = string.Format("Receipt sent {0}. No File downloaded and no File uploaded", s.receipt_sent_date.ToString());
                    }
                    else
                    {
                        Tuple<int, string> status = CheckPaymentStatus(s.company_id, s.tier, s.contributiontype, s.month, s.year, s.contributiontypeid, s.ptas_fund_deal_id);
                        s.workflow_status = (status.Item2 == "Linked") ? Constants.WF_STATUS_PAYMENTS_LINKED : Constants.WF_STATUS_PAYMENTS_RECEIVED;
                        s.workflow_summary = "Schedule linked to Payments. Waiting for Receipt to be sent and File download & uploaded";
                    }

                    // Expire old notifications and send a new one for the file download.
                    ExpireByJob(Constants.NF_TYPE_SCHEDULE_FILE_UPLOAD_REQUEST, Constants.JOB_TYPE_SCHEDULE, s.id);
                    UpdateNotificationStatus(s.id, Constants.NF_TYPE_SCHEDULE_FILE_DOWNLOAD_REQUEST, Constants.SETTINGS_TIME_FILE_DOWNLOAD_INTERVAL);
                }
                else
                {
                    UpdateNotificationStatus(s.id, Constants.NF_TYPE_SCHEDULE_FILE_UPLOAD_REQUEST, Constants.SETTINGS_TIME_FILE_UPLOAD_INTERVAL);
                }
            }
            return s;
        }
Example #9
0
        private static Schedule EvaluatePaymentReceivedSchedule(Schedule s)
        {
            s.processing = true;
            SaveSchedule(s);

            if (s.receipt_sent && s.file_downloaded && s.file_uploaded)
            {
                s.workflow_status = Constants.WF_STATUS_COMPLETED;
                s.workflow_summary = string.Format("Receipt sent {0} and File downloaded {1} and File uploaded {2}", s.receipt_sent_date.ToString(), s.file_downloaded_date.ToString(), s.file_uploaded_date.ToString());
            }
            else if (s.receipt_sent && s.file_downloaded && !s.file_uploaded)
            {
                s.workflow_status = Constants.WF_STATUS_RF_SENT_DOWNLOAD_NOUPLOAD;
                s.workflow_summary = string.Format("Receipt sent {0} and File downloaded {1}. No File uploaded", s.receipt_sent_date.ToString(), s.file_downloaded_date.ToString());
                s = EvaluateFileUploadNotificationStatus(s);
            }
            else if (s.receipt_sent && !s.file_downloaded && !s.file_uploaded)
            {
                s.workflow_status = Constants.WF_STATUS_RF_SENT_NODOWNLOAD_NOUPLOAD;
                s.workflow_summary = string.Format("Receipt sent {0}. No File downloaded and no File uploaded", s.receipt_sent_date.ToString());
                UpdateNotificationStatus(s.id, Constants.NF_TYPE_SCHEDULE_FILE_DOWNLOAD_REQUEST, Constants.SETTINGS_TIME_FILE_DOWNLOAD_INTERVAL);
            }
            else if (!s.receipt_sent && s.file_downloaded && s.file_uploaded)
            {
                s.workflow_status = Constants.WF_STATUS_RF_NOSENT_DOWNLOAD_UPLOAD;
                s.workflow_summary = string.Format("No Receipt sent. File downloaded {0} and File uploaded {1}", s.file_downloaded_date.ToString(), s.file_uploaded_date.ToString());
                UpdateNotificationStatus(s.id, Constants.NF_TYPE_SCHEDULE_RECEIPT_SEND_REQUEST, Constants.SETTINGS_TIME_INTERVAL_SEND_RECEIPT);
            }
            else if (!s.receipt_sent && s.file_downloaded && !s.file_uploaded)
            {
                s.workflow_status = Constants.WF_STATUS_RF_NOSENT_DOWNLOAD_NOUPLOAD;
                s.workflow_summary = string.Format("No Receipt sent. File downloaded {0} and no File uploaded", s.file_downloaded_date.ToString());
                UpdateNotificationStatus(s.id, Constants.NF_TYPE_SCHEDULE_RECEIPT_SEND_REQUEST, Constants.SETTINGS_TIME_INTERVAL_SEND_RECEIPT);
                s = EvaluateFileUploadNotificationStatus(s);
            }
            else if (!s.receipt_sent && !s.file_downloaded && !s.file_uploaded)
            {
                Tuple<int, string> status = CheckPaymentStatus(s.company_id, s.tier, s.contributiontype, s.month, s.year, s.contributiontypeid, s.ptas_fund_deal_id);
                s.workflow_status = (status.Item2=="Linked") ? Constants.WF_STATUS_PAYMENTS_LINKED: Constants.WF_STATUS_PAYMENTS_RECEIVED;
                s.workflow_summary = "Schedule linked to Payments. Waiting for Receipt to be sent and File download & uploaded";
                UpdateNotificationStatus(s.id, Constants.NF_TYPE_SCHEDULE_RECEIPT_SEND_REQUEST, Constants.SETTINGS_TIME_INTERVAL_SEND_RECEIPT);
                UpdateNotificationStatus(s.id, Constants.NF_TYPE_SCHEDULE_FILE_DOWNLOAD_REQUEST, Constants.SETTINGS_TIME_FILE_DOWNLOAD_INTERVAL);
            }
            else
            {
                // Shouldn't reach here..but we should handle file_uploaded, but not downloaded yet issue. how?
            }

            s.processing = false;
            SaveSchedule(s);

            return s;
        }
Example #10
0
 private static void EvaluatePassedSchedule(Schedule s)
 {
     if (s.payment_id == 0 || s.payment_id == null)
     {
         // Check payments
         Tuple<int,string>  status = CheckPaymentStatus(s.company_id, s.tier, s.contributiontype, s.month, s.year, s.contributiontypeid, s.ptas_fund_deal_id);
         if (status.Item1 == 0)
         {
             // No payments found. Will check later
             s.processing = false;
             SaveSchedule(s);
         }
         else
         {
             s.payment_id = status.Item1;
             s = SaveSchedule(s);
             s.workflow_status = (status.Item2=="Linked") ?  Constants.WF_STATUS_PAYMENTS_LINKED : Constants.WF_STATUS_PAYMENTS_RECEIVED;
             s.workflow_summary = "Schedule linked to Payments. Waiting for Receipt to be sent and File download & uploaded";
             EvaluatePaymentReceivedSchedule(s);
         }
     }
     else
     {
         EvaluatePaymentReceivedSchedule(s);
     }    
 }
Example #11
0
        private static Schedule EvaluateReminderStatus(Schedule s)
        {
            bool vsent = (s.validation_email_sent ==null)? false: (bool)s.validation_email_sent;
            bool escalated = (s.escalation_email_sent==null) ? false : (bool)s.escalation_email_sent;
            string errmsg = ""; //string.Format("{0}", s.validation_status);

            if (escalated)
            {
                ExpireByJob(Constants.NF_TYPE_SCHEDULE_VALIDATION_REQUEST, Constants.JOB_TYPE_SCHEDULE, s.id);

                ExpireByJob(Constants.NF_TYPE_SCHEDULE_ERRORFIX_REQUEST, Constants.JOB_TYPE_SCHEDULE, s.id);

                s.workflow_summary = (vsent) ? string.Format("{0} Issue escalated on {1}. Email sent to client on {2}.", errmsg, s.escalation_email_date,s.validation_email_date)
                                           : string.Format("{0} Issue escalated on {1}.",errmsg, s.escalation_email_date);
            }
            else
            {
                Notification nf = GetNotificationByJob(Constants.NF_TYPE_SCHEDULE_ERRORFIX_REQUEST,
                                                           Constants.JOB_TYPE_SCHEDULE,
                                                           s.id);
                DateTime now = DateTime.Now;


                if (nf != null)
                {
                    // Let's go through the escalation process 
                    if ((now.Subtract(s.created_at).Days * 24) > int.Parse(GetSetting(Constants.SETTINGS_TIME_ERRORFIX_3_REMINDER_WINDOW)))
                    {
                        if (nf.times_sent == 2) // It's the 5th day, escalate
                        {
                            // Expire old notification
                            nf.times_sent += 1;
                            nf.last_sent = DateTime.Now;
                            nf.status = Constants.NF_STATUS_EXPIRED;
                            SaveNotification(nf);
                            s.workflow_summary = (vsent) ? string.Format("{0}. 4th and final notification request sent. Email sent to client on {1}. Please escalate issue.", errmsg, s.validation_email_date)
                                                        : string.Format("{0} 4th and final notification request sent. Please escalate issue.",errmsg);
                        }
                    }
                    else if ((now.Subtract(s.created_at).Days * 24) > int.Parse(GetSetting(Constants.SETTINGS_TIME_ERRORFIX_2_REMINDER_WINDOW)))
                    {
                        if (nf.times_sent == 1) // It's the 3rd day, send a remider
                        {
                            nf.times_sent += 1;
                            nf.last_sent = DateTime.Now;
                            nf.status = Constants.NF_STATUS_NEW;
                            SaveNotification(nf);
                            s.workflow_summary = (vsent) ? string.Format("{0} 3rd notification request sent. Email sent to client on {1}.", errmsg, s.validation_email_date)
                                                     :  string.Format("{0} 3rd notification request sent.",errmsg);
                        }
                    }
                    else
                    {
                        s.workflow_summary = (vsent) ? string.Format("{0} 2nd notification request sent. Email sent to client on {1}.", errmsg, s.validation_email_date)
                                                     :  string.Format("{0} 2nd notification request sent.",errmsg);
                    }
                }
                else
                {
                    // Notification has not been sent. It's the 2nd day, send a reminder
                    if ((now.Subtract(s.created_at).Days * 24) > int.Parse(GetSetting(Constants.SETTINGS_TIME_ERRORFIX_1_REMINDER_WINDOW)))
                    {
                        AddNotification(Constants.ROLES_OPS_USER_ID, Constants.NF_TYPE_SCHEDULE_ERRORFIX_REQUEST, Constants.JOB_TYPE_SCHEDULE, s.id);
                        s.workflow_summary = (vsent) ? string.Format("{0} 2nd notification request sent. Email sent to client on {1}.", errmsg, s.validation_email_date)
                                                     :  string.Format("{0} 2nd notification request sent.",errmsg);
                    }
                    else
                    {
                        s.workflow_summary = (vsent) ? string.Format("{0} 1st notification request sent. Email sent to client on {1}.", errmsg, s.validation_email_date)
                                      :  string.Format("{0} 1st notification request sent yet.",errmsg);
                    }
                }
            }
            
            s.processing = false;
            SaveSchedule(s);

            return s;
        }