public static void FinalizeStoreInPast() { GetAndValidateFinalizeData(); DateTime yesterday = DateTime.Now.Date.AddDays(-1); DateTime startDate = lastFinalizeDate.HasValue ? lastFinalizeDate.Value.Date.AddDays(1) : yesterday; for (DateTime i = startDate; i < DateTime.Now.Date; i = i.Date.AddDays(1)) { StoreFinalizeBLL.FinalizeStore(i, false); } LogBLL.Logs(); }
public static void FinalizeStore(DateTime date, bool overwrite) { string err = "Process for day: " + date.Date.ToShortDateString() + ". "; DateTime?firstFinalizeDate; DateTime?lastFinalizeDate; DateTime?lastPackTransactionDate; DateTime?firstPackTransactionDate; DateTime?lastBackupPackRemainDate; RedBloodSystemBLL.GetLastFinalizeDate(out firstFinalizeDate, out lastFinalizeDate, out lastPackTransactionDate, out firstPackTransactionDate, out lastBackupPackRemainDate); if (date.Date > DateTime.Now.Date || lastFinalizeDate.HasValue && lastFinalizeDate.Value.Date > DateTime.Now.Date || (lastPackTransactionDate.HasValue && lastPackTransactionDate.Value.Date > DateTime.Now.Date) || (lastBackupPackRemainDate.HasValue && lastBackupPackRemainDate.Value.Date > DateTime.Now.Date) ) { LogBLL.LogsFailAndThrow(err + "Error. Data or Date in future."); } //Data in DB is newer. Data error or system datetime error if ( (lastFinalizeDate.HasValue && lastFinalizeDate.Value.Date > date.Date) || (lastPackTransactionDate.HasValue && lastPackTransactionDate.Value.Date > date.Date) || (lastBackupPackRemainDate.HasValue && lastBackupPackRemainDate.Value.Date > date.Date) ) { LogBLL.LogsFailAndThrow(err + "Newer data in DB."); } if (lastFinalizeDate.HasValue) { int daysBefore = (date.Date - lastFinalizeDate.Value.Date).Days; if (daysBefore != 0 && daysBefore != 1) { LogBLL.LogsFailAndThrow(err + "Data should be finalized with in or 1 day before."); } if (daysBefore == 0) { if (overwrite) { //Clear StoreFinalizes StoreFinalizeBLL.Clear(date); //Clear PackRemainDailies PackRemainDailyBLL.Clear(date); } else { LogBLL.LogsFailAndThrow(err + "Aldready finilized. Set overwrite=true to re-finilized."); } } } StoreFinalizeBLL.CountPackTransaction(date).Select(r => StoreFinalizeBLL.Add(r.Date.Value, r.Type, r.Count.Value)).ToList(); StoreFinalizeBLL.Add(date, PackTransaction.TypeX.Remain, StoreFinalizeBLL.CountPackRemainByPackStatus()); PackRemainDailyBLL.Backup(date); LogBLL.Logs(err); }