public void testBookingPeriod() { int btId = dbType.addNewRecord("newName", "newProducer", 10, 100); //capacity equals 10 hours int bId = dbBattery.addNewRecord("Charged", btId); int sID = dbStation.addNewRecord("newName", "newAddress", "newCountry", "newState"); int bsID = dbStorage.addNewRecord(btId, sID, 20); dbPeriod.addNewRecord(bsID, DateTime.Today, 10,5); // initial =10 custom = 5 period = dbPeriod.getRecord(bsID, DateTime.Today, true); storage = dbStorage.getRecord(bsID, true); DateTime time = new DateTime(); time = DateTime.Today.AddDays(10); DateTime secondTime = DateTime.Today.AddDays(5); try { period = pCalc.getBookingPeriod(storage, time); MPeriod previous = pCalc.getPreviousPeriod(storage, period); Assert.AreEqual(isInPeriod(period, time, storage), true); period = pCalc.getBookingPeriod(storage, secondTime); Assert.AreEqual(isInPeriod(period, secondTime, storage), true); } finally { storage = dbStorage.getRecord(storage.id,true); foreach (MPeriod p in storage.periods) { dbPeriod.deleteRecord(bsID,p.time); } dbStorage.deleteRecord(bsID); dbStation.deleteRecord(sID); dbBattery.deleteRecord(bId); dbType.deleteRecord(btId); } }
private Boolean isTimeEligible() { MPeriod mon = package.MondayPeriod; MPeriod tue = package.TuesdayPeriod; MPeriod wed = package.WednesdayPeriod; MPeriod thu = package.ThursdayPeriod; MPeriod fri = package.FridayPeriod; MPeriod sat = package.SathurdayPeriod; MPeriod sun = package.SundayPeriod; ArrayList periods = new ArrayList(); periods.Add(mon); periods.Add(tue); periods.Add(wed); periods.Add(thu); periods.Add(fri); periods.Add(sat); periods.Add(sun); foreach (MPeriod p in periods) { if (isPeriodOK(p)) { return(true); } } return(false); }
public void TestValidateBooking1() { IDStation dbStation = new DStation(); IDBatteryType dbType = new DBatteryType(); IDBBatteryStorage dbStorage = new DBBatteryStorage(); IDPeriod dbPeriod = new DBPeriod(); int sid = dbStation.addNewRecord("name", "address", "country", "state"); int btid = dbType.addNewRecord("name", "producer", 10, 10); int bsid = dbStorage.addNewRecord(btid, sid, 10); MBatteryStorage storage = dbStorage.getRecord(bsid, true); try { MPeriod firstPeriod = new MPeriod(); firstPeriod.bookedBatteryNumber = 6; firstPeriod.initBatteryNumber = 10; firstPeriod.time = DateTime.Today; dbPeriod.addNewRecord(bsid, firstPeriod.time, firstPeriod.initBatteryNumber, firstPeriod.bookedBatteryNumber); storage.periods.Add(firstPeriod); MPeriod testPeriod = new MPeriod(); testPeriod.time = DateTime.Today.AddHours(10); testPeriod.initBatteryNumber = 10; testPeriod.bookedBatteryNumber = 4; dbPeriod.addNewRecord(bsid, testPeriod.time, testPeriod.initBatteryNumber, testPeriod.bookedBatteryNumber); storage.periods.Add(testPeriod); MPeriod lastPeriod = new MPeriod(); lastPeriod.time = DateTime.Today.AddHours(20); lastPeriod.initBatteryNumber = 10; lastPeriod.bookedBatteryNumber = 5; dbPeriod.addNewRecord(bsid, lastPeriod.time, lastPeriod.initBatteryNumber, lastPeriod.bookedBatteryNumber); storage.periods.Add(lastPeriod); BatteryStorageCtr storageCtr = new BatteryStorageCtr(); if (storageCtr.validateBookingForStation(sid, btid, 1, DateTime.Today.AddHours(10))) { Assert.AreEqual(2, 1); } else { Assert.AreEqual(1, 1); //it should fail } if (storageCtr.validateUpdateBookingForStation(sid, btid, 1, DateTime.Today.AddHours(10))) { Assert.AreEqual(2, 1); } else { Assert.AreEqual(1, 1); //it should fail } } finally { foreach (MPeriod p in storage.periods) { dbPeriod.deleteRecord(bsid, p.time); } dbStorage.deleteRecord(bsid); dbType.deleteRecord(btid); dbStation.deleteRecord(sid); } }
public String PrepareIt() { MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID()); if (!MPeriod.IsOpen(GetCtx(), GetDateAcct(), dt.GetDocBaseType())) { _processMsg = "@PeriodClosed@"; return(DocActionVariables.STATUS_INVALID); } // is Non Business Day? if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateAcct())) { _processMsg = VAdvantage.Common.Common.NONBUSINESSDAY; return(DocActionVariables.STATUS_INVALID); } if (IsVA027_MultiCheque()) { if (Util.GetValueOfInt(DB.ExecuteScalar("Select Count(*) From VA027_ChequeDetails Where VA027_PostDatedCheck_ID=" + GetVA027_PostDatedCheck_ID(), null, Get_Trx())) <= 0) { _processMsg = "@NoLinesFound@"; return(DocActionVariables.STATUS_INVALID); } } return(DocActionVariables.STATUS_INPROGRESS); }
public void createFirstPeriod(int storageID) { MBatteryStorage storage = dbStorage.getRecord(storageID, true); MPeriod period = new MPeriod(); period.bookedBatteryNumber = 0; period.initBatteryNumber = getInitNumber(storage); period.time = DateTime.Today.AddDays(1); dbPeriod.addNewRecord(storage.id, period.time, period.initBatteryNumber, period.bookedBatteryNumber); }
public MPeriod createPeriod(MBatteryStorage storage) { storage = dbStorage.getRecord(storage.id, true); MPeriod newPeriod = new MPeriod(); newPeriod.time = getTime(storage); newPeriod.initBatteryNumber = getInitNumber(storage); dbPeriod.addNewRecord(storage.id, newPeriod.time, newPeriod.initBatteryNumber, newPeriod.bookedBatteryNumber); return newPeriod; }
} // setClientOrg /// <summary> /// Get Period /// </summary> /// <returns>period or null</returns> public MPeriod GetPeriod() { int C_Period_ID = GetC_Period_ID(); if (C_Period_ID != 0) { return(MPeriod.Get(GetCtx(), C_Period_ID)); } return(null); } // getPeriod
/// <summary> /// Process /// </summary> /// <returns>message</returns> protected override String DoIt() { MPeriod period = new MPeriod(GetCtx(), _C_Period_ID, Get_Trx()); // Get all Document type related to Tenant MDocType[] types = MDocType.GetOfClient(GetCtx()); int count = 0; List <String> baseTypes = new List <String>(); ValueNamePair vp = null; // Split multiselected organizations to get array if (!String.IsNullOrEmpty(orgs)) { _AD_Org_ID = orgs.Split(','); } for (int i = 0; i < types.Length; i++) { MDocType type = types[i]; String docBaseType = type.GetDocBaseType(); if (baseTypes.Contains(docBaseType)) { continue; } // loop on multiple selected organizations for (int j = 0; j < _AD_Org_ID.Length; j++) { MPeriodControl pc = new MPeriodControl(period, docBaseType); pc.SetAD_Org_ID(Util.GetValueOfInt(_AD_Org_ID[j])); if (pc.Save()) { count++; } else { vp = VLogger.RetrieveError(); if (vp != null) { log.Severe(Msg.GetMsg(GetCtx(), "PeriodCtlNotSaved") + ", " + vp.GetName()); } else { log.Severe(Msg.GetMsg(GetCtx(), "PeriodCtlNotSaved")); } } } baseTypes.Add(docBaseType); } log.Fine("PeriodControl #" + count); return(Msg.GetMsg(GetCtx(), "PeriodControlGenerated")); }
public bool isInPeriod(MPeriod period, DateTime time, MBatteryStorage storage) { DateTime first = period.time; double hours = (double) storage.type.capacity; DateTime second = period.time.AddHours(hours); if ((time.CompareTo(first) >= 0) & (time.CompareTo(second) < 0)) { return true; } else return false; }
/// <summary> /// Get Period /// </summary> /// <param name="ctx">Context</param> /// <param name="fields">Parameter</param> /// <returns>Period ID</returns> public int GetPeriod(Ctx ctx, string fields) { string[] paramValue = fields.Split(','); int period_ID; int AD_Client_ID = Util.GetValueOfInt(paramValue[0]); DateTime?dateAcct = Util.GetValueOfDateTime(paramValue[1]); int AD_Org_ID = Util.GetValueOfInt(paramValue[2]); period_ID = MPeriod.GetC_Period_ID(ctx, dateAcct, AD_Org_ID); return(period_ID); }
/// <summary> /// Before Delete /// </summary> /// <returns>true if acct was deleted</returns> protected override bool BeforeDelete() { if (IsPosted()) { if (!MPeriod.IsOpen(GetCtx(), GetDateTrx(), MDocBaseType.DOCBASETYPE_MATCHPO)) { return(false); } SetPosted(false); return(true);// MFactAcct.Delete(Table_ID, Get_ID(), Get_Trx()) >= 0; } return(true); }
/// <summary> /// Check to see if the appropriate periods are open for this document /// </summary> /// <param name="doc">Doc</param> /// <returns>null if all periods open; otherwise the error message</returns> public static String IsPeriodOpen(DocAction doc) { List <int> docOrgs = new List <int>(); String errorMsg = null; if (errorMsg == null) { // check if lines exist // get all the orgs stamped on the document lines VAdvantage.Utility.Env.QueryParams qParams = doc.GetLineOrgsQueryInfo(); if (qParams != null) { //Object[][] result = QueryUtil.ExecuteQuery(doc.Get_Trx(), qParams.sql, // qParams.parameters.ToList()); Object[][] result = VAdvantage.Utility.QueryUtil.ExecuteQuery(doc.Get_Trx(), qParams.sql, qParams.parameters.ToList()); foreach (Object[] row in result) { docOrgs.Add(Utility.Util.GetValueOfInt(Utility.Util.GetValueOfDecimal(row[0]))); } // check if lines are missing if (result.Length == 0) { errorMsg = "@NoLines@"; } } } if (errorMsg == null) { DateTime?docDate = doc.GetDocumentDate(); String docBaseType = doc.GetDocBaseType(); if (docDate != null && docBaseType != null) { // check if period is open // add doc header org to the list of orgs if (!docOrgs.Contains(doc.GetAD_Org_ID())) { docOrgs.Add(doc.GetAD_Org_ID()); } // Std Period open? errorMsg = MPeriod.IsOpen(doc.GetCtx(), doc.GetAD_Client_ID(), docOrgs, docDate, docBaseType); } } return(errorMsg); }
public List<MPeriod> getAllPeriodsAfter(MBatteryStorage storage, MPeriod period) { List<MPeriod> periods = dbPeriod.getStoragePeriods(storage.id, true); bool found = false; List<MPeriod> periodsAfter = new List<MPeriod>(); foreach (MPeriod p in periods) { if (p.time == period.time) { found = true; } if (found) { periodsAfter.Add(p); } } return periodsAfter; }
private Boolean isPeriodOK(MPeriod p) { Hashtable days = new Hashtable(); days[1] = DayOfWeek.Monday; days[2] = DayOfWeek.Tuesday; days[3] = DayOfWeek.Wednesday; days[4] = DayOfWeek.Thursday; days[5] = DayOfWeek.Friday; days[6] = DayOfWeek.Saturday; days[7] = DayOfWeek.Sunday; DayOfWeek d = (DayOfWeek)days[CUtil.StringToInt(p.DayOfWeek)]; if (d != billDate.DayOfWeek) { return(false); } if (!p.IsEnabled) { return(false); } if (p.IsEnabled && (p.PeriodType == IntervalTypeEnum.DAY_ENTIRE)) { //All day return(true); } String fromHHMM = String.Format("{0}:{1}", p.FromHour1, p.FromMinute1); String toHHMM = String.Format("{0}:{1}", p.ToHour1, p.ToMinute1); String currTime = CUtil.DateTimeToDateStringTime(billTime).Substring(11, 5); if ((currTime.CompareTo(fromHHMM) >= 0) && (currTime.CompareTo(toHHMM) <= 0)) { return(true); } return(false); }
} // setDateAcct /// <summary> /// Set Period /// </summary> /// <param name="C_Period_ID">period</param> public new void SetC_Period_ID(int C_Period_ID) { //super.setC_Period_ID(C_Period_ID); base.SetC_Period_ID(C_Period_ID); if (C_Period_ID == 0) { return; } DateTime?dateAcct = GetDateAcct(); // MPeriod period = GetPeriod(); if (period != null) { if (period.IsStandardPeriod() && !period.IsInPeriod(dateAcct)) { base.SetDateAcct(period.GetEndDate()); } } } // setC_Period_ID
} // setC_Period_ID /// <summary> /// Set Accounting Date.Set also Period if not set earlier /// </summary> /// <param name="DateAcct">date</param> public void SetDateAcct(DateTime DateAcct) { //super.setDateAcct(DateAcct); base.SetDateAcct(DateAcct); if (GetC_Period_ID() != 0) // previously set { SetRate(); return; } int C_Period_ID = MPeriod.GetC_Period_ID(GetCtx(), DateAcct); if (C_Period_ID == 0) { log.Warning("Period not found"); } else { base.SetC_Period_ID(C_Period_ID); SetRate(); } } // setDateAcct
public MPeriod getNextPeriod(MBatteryStorage storage, MPeriod current) { List<MPeriod> periods = dbPeriod.getStoragePeriods(storage.id, true); int x = 0; bool found = false; MPeriod next = new MPeriod(); while (!found || x < periods.Count) { MPeriod period = periods[x]; if (period.time == current.time) { found = true; try { next = periods[x + 1]; } catch (Exception) { next = createPeriod(storage); } } x++; } return next; }
public bool ReverseCorrectIt() { try { MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID()); if (!MPeriod.IsOpen(GetCtx(), GetDateAcct(), dt.GetDocBaseType())) { _processMsg = "@PeriodClosed@"; return(false); } // is Non Business Day? if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateAcct())) { _processMsg = VAdvantage.Common.Common.NONBUSINESSDAY; return(false); } //commented by arpit //if (!IsVA027_PaymentGenerated()) //{ // _processMsg = "Payment Not Generated Yet"; // Get_Trx().Rollback(); // return false; //} //end here if (GetC_Payment_ID() > 0) { MPayment pay = new MPayment(GetCtx(), GetC_Payment_ID(), Get_Trx()); if (pay.GetDocStatus() != "RE" && pay.GetDocStatus() != "VO") { _processMsg = Msg.GetMsg(GetCtx(), "VA027_PaymentNotVoid"); Get_Trx().Rollback(); return(false); } } MVA027PostDatedCheck reversal = new MVA027PostDatedCheck(GetCtx(), 0, Get_Trx()); CopyValues(this, reversal); reversal.SetClientOrg(this); reversal.SetVA027_PayAmt(Decimal.Negate(reversal.GetVA027_PayAmt())); reversal.SetDocumentNo(GetDocumentNo() + REVERSE_INDICATOR); if (!string.IsNullOrEmpty(GetVA027_CheckNo())) { reversal.SetVA027_CheckNo(GetVA027_CheckNo() + REVERSE_INDICATOR); } reversal.SetDocStatus(DOCSTATUS_Drafted); reversal.SetDocAction(DOCACTION_Complete); reversal.SetProcessed(false); reversal.SetProcessing(false); reversal.SetPosted(false); reversal.SetVA027_Description(GetVA027_Description()); reversal.AddDescription("{->" + GetDocumentNo() + ")"); if (reversal.Save(Get_Trx())) { DataSet ds = new DataSet(); ds = DB.ExecuteDataset("Select * from VA027_CHEQUEDETAILS Where VA027_PostDatedCheck_ID=" + GetVA027_PostDatedCheck_ID(), null, Get_Trx()); if (ds != null && ds.Tables[0].Rows.Count > 0) { for (Int32 i = 0; i < ds.Tables[0].Rows.Count; i++) { MVA027ChequeDetails original = new MVA027ChequeDetails(GetCtx(), Util.GetValueOfInt(ds.Tables[0].Rows[i]["VA027_CHEQUEDETAILS_ID"]), Get_Trx()); MVA027ChequeDetails cd = new MVA027ChequeDetails(GetCtx(), 0, Get_Trx()); if (original.GetC_Payment_ID() > 0) { MPayment payment = new MPayment(GetCtx(), original.GetC_Payment_ID(), Get_Trx()); if (payment.GetDocStatus() != "RE" && payment.GetDocStatus() != "VO") { _processMsg = Msg.GetMsg(GetCtx(), "VA027_PaymentNotVoid"); Get_Trx().Rollback(); return(false); } } cd.SetAD_Client_ID(original.GetAD_Client_ID()); cd.SetAD_Org_ID(original.GetAD_Org_ID()); cd.SetVA027_AccountName(original.GetVA027_AccountName()); cd.SetLineNo(original.GetLineNo()); cd.SetVA027_PostDatedCheck_ID(reversal.GetVA027_PostDatedCheck_ID()); cd.SetVA027_AccountNo(original.GetVA027_AccountNo()); cd.SetVA027_CheckDate(original.GetVA027_CheckDate()); cd.SetVA027_CheckNo(original.GetVA027_CheckNo() + REVERSE_INDICATOR); cd.SetVA027_ChequeAmount(Decimal.Negate(original.GetVA027_ChequeAmount())); cd.SetVA027_MICR(original.GetVA027_MICR()); cd.SetVA027_PaymentStatus("3"); cd.SetVA027_ValidMonth(original.GetVA027_ValidMonth()); cd.SetProcessed(true); cd.Save(Get_Trx()); } } } if (!reversal.ProcessIt(DocActionVariables.ACTION_COMPLETE)) { _processMsg = "Reversal ERROR: " + reversal.GetProcessMsg(); return(false); } reversal.CloseIt(); _processMsg = reversal.GetDocumentNo(); reversal.SetVA027_PaymentStatus("3"); reversal.SetDocStatus(DOCSTATUS_Reversed); reversal.SetDocAction(DOCACTION_None); reversal.Save(Get_Trx()); this.AddDescription("(" + GetDocumentNo() + "<-)"); SetDocStatus(DOCSTATUS_Reversed); SetDocAction(DOCACTION_None); SetProcessed(true); } catch (Exception ex) { log.Severe(ex.ToString()); log.Severe("Error in Reverse."); } return(true); }
public MPeriod getPreviousPeriod(MBatteryStorage storage, MPeriod current) { List<MPeriod> periods = dbPeriod.getStoragePeriods(storage.id, true); int x = periods.Count; bool found = false; MPeriod previous = new MPeriod(); while(!found || x>0) { MPeriod period = periods[x-1]; if (period.time == current.time) { found = true; try { previous = periods[x - 2]; } catch (ArgumentOutOfRangeException) { } } x--; } return previous; }
} // doIt /// <summary> /// Create Beginning Balance Line /// </summary> private void CreateBalanceLine() { StringBuilder sql = new StringBuilder(_insert); // (AD_PInstance_ID, Fact_Acct_ID, sql.Append("SELECT ").Append(GetAD_PInstance_ID()).Append(",0,"); // AD_Client_ID, AD_Org_ID, Created,CreatedBy, Updated,UpdatedBy, sql.Append(GetAD_Client_ID()).Append(","); if (_AD_Org_ID == 0 || _AD_Org_ID == -1) { sql.Append("0"); } else { sql.Append(_AD_Org_ID); } sql.Append(", SysDate,").Append(GetAD_User_ID()) .Append(",SysDate,").Append(GetAD_User_ID()).Append(","); // C_AcctSchema_ID, Account_ID, AccountValue, DateTrx, DateAcct, C_Period_ID, sql.Append(_C_AcctSchema_ID).Append(","); if (_Account_ID == 0 || _Account_ID == -1) { sql.Append("null"); } else { sql.Append(_Account_ID); } if (_AccountValue_From != null) { sql.Append(",").Append(DataBase.DB.TO_STRING(_AccountValue_From)); } else if (_AccountValue_To != null) { sql.Append(",' '"); } else { sql.Append(",null"); } DateTime?balanceDay = _DateAcct_From; // TimeUtil.addDays(_DateAcct_From, -1); sql.Append(",null,").Append(DataBase.DB.TO_DATE(balanceDay, true)).Append(","); if (_C_Period_ID == 0 || _C_Period_ID == -1) { sql.Append("null"); } else { sql.Append(_C_Period_ID); } sql.Append(","); // AD_Table_ID, Record_ID, Line_ID, sql.Append("null,null,null,"); // GL_Category_ID, GL_Budget_ID, C_Tax_ID, M_Locator_ID, PostingType, sql.Append("null,null,null,null,'").Append(_PostingType).Append("',"); // C_Currency_ID, AmtSourceDr, AmtSourceCr, AmtSourceBalance, sql.Append("null,null,null,null,"); // AmtAcctDr, AmtAcctCr, AmtAcctBalance, C_UOM_ID, Qty, sql.Append(" COALESCE(SUM(AmtAcctDr),0),COALESCE(SUM(AmtAcctCr),0)," + "COALESCE(SUM(AmtAcctDr),0)-COALESCE(SUM(AmtAcctCr),0)," + " null,COALESCE(SUM(Qty),0),"); // M_Product_ID, C_BPartner_ID, AD_OrgTrx_ID, C_LocFrom_ID,C_LocTo_ID, if (_M_Product_ID == 0 || _M_Product_ID == -1) { sql.Append("null"); } else { sql.Append(_M_Product_ID); } sql.Append(","); if (_C_BPartner_ID == 0 || _C_BPartner_ID == -1) { sql.Append("null"); } else { sql.Append(_C_BPartner_ID); } sql.Append(","); if (_AD_OrgTrx_ID == 0 || _AD_OrgTrx_ID == -1) { sql.Append("null"); } else { sql.Append(_AD_OrgTrx_ID); } sql.Append(","); if (_C_LocFrom_ID == 0 || _C_LocFrom_ID == -1) { sql.Append("null"); } else { sql.Append(_C_LocFrom_ID); } sql.Append(","); if (_C_LocTo_ID == 0 || _C_LocTo_ID == -1) { sql.Append("null"); } else { sql.Append(_C_LocTo_ID); } sql.Append(","); // C_SalesRegion_ID, C_Project_ID, C_Campaign_ID, C_Activity_ID, if (_C_SalesRegion_ID == 0 || _C_SalesRegion_ID == -1) { sql.Append("null"); } else { sql.Append(_C_SalesRegion_ID); } sql.Append(","); if (_C_Project_ID == 0 || _C_Project_ID == -1) { sql.Append("null"); } else { sql.Append(_C_Project_ID); } sql.Append(","); if (_C_Campaign_ID == 0 || _C_Campaign_ID == -1) { sql.Append("null"); } else { sql.Append(_C_Campaign_ID); } sql.Append(","); if (_C_Activity_ID == 0 || _C_Activity_ID == -1) { sql.Append("null"); } else { sql.Append(_C_Activity_ID); } sql.Append(","); // User1_ID, User2_ID, A_Asset_ID, Description) if (_User1_ID == 0 || _User1_ID == -1) { sql.Append("null"); } else { sql.Append(_User1_ID); } sql.Append(","); if (_User2_ID == 0 || _User2_ID == -1) { sql.Append("null"); } else { sql.Append(_User2_ID); } sql.Append(", null,null"); // sql.Append(" FROM Fact_Acct WHERE AD_Client_ID=").Append(GetAD_Client_ID()) .Append(" AND ").Append(m_parameterWhere) .Append(" AND DateAcct < ").Append(DataBase.DB.TO_DATE(_DateAcct_From, true)); // Start Beginning of Year if (_Account_ID > 0) { m_acct = new MElementValue(GetCtx(), _Account_ID, Get_Trx()); if (!m_acct.IsBalanceSheet()) { MPeriod first = MPeriod.GetFirstInYear(GetCtx(), _DateAcct_From); if (first != null) { sql.Append(" AND DateAcct >= ").Append(DataBase.DB.TO_DATE(first.GetStartDate(), true)); } else { log.Log(Level.SEVERE, "first period not found"); } } } // int no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_Trx()); if (no == 0) { log.Fine(sql.ToString()); } log.Fine("#" + no + " (Account_ID=" + _Account_ID + ")"); } // createBalanceLine
} // invalidateIt /// <summary> /// Prepare Document /// </summary> /// <returns>new status (In Progress or Invalid) </returns> public String PrepareIt() { log.Info(ToString()); m_processMsg = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_BEFORE_PREPARE); if (m_processMsg != null) { return(DocActionVariables.STATUS_INVALID); } MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID()); // Get Period MPeriod period = MPeriod.Get(GetCtx(), GetDateAcct()); if (period == null) { log.Warning("No Period for " + GetDateAcct()); m_processMsg = "@PeriodNotFound@"; return(DocActionVariables.STATUS_INVALID); } // Standard Period if (period.GetC_Period_ID() != GetC_Period_ID() && period.IsStandardPeriod()) { m_processMsg = "@PeriodNotValid@"; return(DocActionVariables.STATUS_INVALID); } Boolean open = period.IsOpen(dt.GetDocBaseType()); if (!open) { log.Warning(period.GetName() + ": Not open for " + dt.GetDocBaseType() + " (" + GetDateAcct() + ")"); m_processMsg = "@PeriodClosed@"; return(DocActionVariables.STATUS_INVALID); } // JID_0521 - Restrict if debit and credit amount is not equal.-Mohit-12-jun-2019. if (GetTotalCr() != GetTotalDr()) { m_processMsg = Msg.GetMsg(GetCtx(), "DBAndCRAmtNotEqual"); return(DocActionVariables.STATUS_INVALID); } // Lines MJournalLine[] lines = GetLines(true); if (lines.Length == 0) { m_processMsg = "@NoLines@"; return(DocActionVariables.STATUS_INVALID); } //Manish 18/7/2016 .. Because if line dimention (Amount) column sum is not equals to debit or credit value complete process will not done. int journalDRAndCR = 0; string getlinevalues = "SELECT NVL(ElementType,null) AS ElementType,AmtSourceDr,AmtAcctCr,AmtSourceCr,GL_JournalLine_ID FROM GL_JournalLine where GL_Journal_ID=" + Get_Value("GL_Journal_ID"); DataSet dts = DB.ExecuteDataset(getlinevalues, null, null); if (dts != null && dts.Tables[0].Rows.Count > 0) { for (int i = 0; i < dts.Tables[0].Rows.Count; i++) { journalDRAndCR = 0; if (dts.Tables[0].Rows[i]["ElementType"].ToString() == "") { continue; } if (Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceDr"]) > 0) { journalDRAndCR = Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceDr"]); } else { if (Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceCr"]) > 0) { journalDRAndCR = Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceCr"]); } } string getlineval = "SELECT SUM(amount) FROM gl_linedimension where GL_JournalLine_ID=" + Convert.ToInt32(dts.Tables[0].Rows[i]["GL_JournalLine_ID"]); int count = Util.GetValueOfInt(DB.ExecuteScalar(getlineval)); if (journalDRAndCR != count) { m_processMsg = "@AmountNotMatch@"; return(DocActionVariables.STATUS_INVALID); } } } // Add up Amounts Decimal AmtSourceDr = Env.ZERO; Decimal AmtSourceCr = Env.ZERO; for (int i = 0; i < lines.Length; i++) { MJournalLine line = lines[i]; if (!IsActive()) { continue; } // if (line.IsDocControlled()) { m_processMsg = "@DocControlledError@ - @Line@=" + line.GetLine() + " - " + line.GetAccountElementValue(); return(DocActionVariables.STATUS_INVALID); } // AmtSourceDr = Decimal.Add(AmtSourceDr, line.GetAmtAcctDr()); AmtSourceCr = Decimal.Add(AmtSourceCr, line.GetAmtAcctCr()); } SetTotalDr(AmtSourceDr); SetTotalCr(AmtSourceCr); // Control Amount if (Env.ZERO.CompareTo(GetControlAmt()) != 0 && GetControlAmt().CompareTo(GetTotalDr()) != 0) { m_processMsg = "@ControlAmtError@"; return(DocActionVariables.STATUS_INVALID); } // Unbalanced Jornal & Not Suspense if (AmtSourceDr.CompareTo(AmtSourceCr) != 0) { MAcctSchemaGL gl = MAcctSchemaGL.Get(GetCtx(), GetC_AcctSchema_ID()); if (gl == null || !gl.IsUseSuspenseBalancing()) { m_processMsg = "@UnbalancedJornal@"; return(DocActionVariables.STATUS_INVALID); } } if (!DOCACTION_Complete.Equals(GetDocAction())) { SetDocAction(DOCACTION_Complete); } m_justPrepared = true; return(DocActionVariables.STATUS_INPROGRESS); } // prepareIt
public void TestGetPeriod() { int btId = dbType.addNewRecord("newName", "newProducer", 10, 100); //capacity equals 10 hours int sID = dbStation.addNewRecord("newName", "newAddress", "newCountry", "newState"); int bsID = dbStorage.addNewRecord(btId, sID, 20); dbPeriod.addNewRecord(bsID, DateTime.Today, 10, 5); // initial =10 custom = 5 future = 1 period = dbPeriod.getRecord(bsID, DateTime.Today, true); storage = dbStorage.getRecord(bsID, true); try { MPeriod firstPeriod = pCalc.createPeriod(storage); storage = dbStorage.getRecord(storage.id, true); MPeriod secondPeriod = pCalc.createPeriod(storage); Assert.AreEqual(DateTime.Today.AddHours(20), secondPeriod.time); Assert.AreEqual(20, secondPeriod.initBatteryNumber); Assert.AreEqual(0, firstPeriod.bookedBatteryNumber); } finally { dbPeriod.deleteRecord(bsID, DateTime.Today); dbPeriod.deleteRecord(bsID, DateTime.Today.AddHours(10)); dbPeriod.deleteRecord(bsID, DateTime.Today.AddHours(20)); dbStorage.deleteRecord(bsID); dbStation.deleteRecord(sID); dbType.deleteRecord(btId); } }
public void TestGetInitNumber() { int btId = dbType.addNewRecord("newName", "newProducer", 10, 100); //capacity equals 10 hours int sID = dbStation.addNewRecord("newName", "newAddress", "newCountry", "newState"); int bsID = dbStorage.addNewRecord(btId, sID, 20); dbPeriod.addNewRecord(bsID, DateTime.Today, 10, 5); // initial =10 custom = 5 future = 1 period = dbPeriod.getRecord(bsID, DateTime.Today, true); storage = dbStorage.getRecord(bsID, true); try { int init = pCalc.getInitNumber(storage); Assert.AreEqual(init, 20); } finally { dbPeriod.deleteRecord(bsID, DateTime.Today); dbStorage.deleteRecord(bsID); dbStation.deleteRecord(sID); dbType.deleteRecord(btId); } }