/// <summary> /// reIndex Document /// </summary> /// <param name="runCleanUp">clean old records</param> /// <param name="toBeIndexed">Array of Strings to be indexed</param> /// <param name="ctx">context</param> /// <param name="AD_Client_ID">id</param> /// <param name="AD_Table_ID">id</param> /// <param name="Record_ID">id</param> /// <param name="CM_WebProject_ID">webproject</param> /// <param name="lastUpdated">date of last update</param> public static void ReIndex(bool runCleanUp, String[] toBeIndexed, Ctx ctx, int AD_Client_ID, int AD_Table_ID, int Record_ID, int CM_WebProject_ID, DateTime?lastUpdated) { Trx trx = Trx.Get("ReIndex_" + AD_Table_ID + "_" + Record_ID); try { if (!runCleanUp) { MIndex.CleanUp(trx, AD_Client_ID, AD_Table_ID, Record_ID); } for (int i = 0; i < toBeIndexed.Length; i++) { MIndex.RunIndex(toBeIndexed[i], ctx, trx, AD_Table_ID, Record_ID, CM_WebProject_ID, lastUpdated); } trx.Commit(); //DataBase.DB.Commit (true, trx); } catch { try { //DataBase.DB.Rollback(true, trx); trx.Rollback(); } catch { } } }
/// <summary> /// Delect recordes from allocation /// </summary> /// <param name="hdr"></param> /// <returns>Bool type</returns> private Boolean Delete(MAllocationHdr hdr) { // _m_trx.start(); Boolean success = false; String msg = null; // Std Period open? msg = DocumentEngine.IsPeriodOpen(hdr); if (msg != null) { msg = "@DeleteError@" + hdr.GetDocumentNo() + ": " + msg; log.Warning(msg); return(false); } if (hdr.Delete(true, _m_trx)) { log.Fine(hdr.ToString()); success = true; } if (success) { _m_trx.Commit(); } else { _m_trx.Rollback(); } return(success); }
/// <summary> /// Process Remote /// @ejb.interface-method view-type="both" /// </summary> /// <param name="ctx">Context</param> /// <param name="pi">Process Info</param> /// <returns>resulting Process Info</returns> public ProcessInfo Process(Ctx ctx, ProcessInfo pi) { String className = pi.GetClassName(); log.Info(className + " - " + pi); _processCount++; // Get Class // Class clazz = null; // XDoclet: no generics! Type clazz = null; try { //clazz = Class.forName (className); clazz = Type.GetType(className); } catch (Exception ex) { log.Log(Level.WARNING, className, ex); pi.SetSummary("ClassNotFound", true); return(pi); } // Get Process SvrProcess process = null; try { //process = (SvrProcess)clazz.newInstance (); process = (SvrProcess)Activator.CreateInstance(clazz); } catch (Exception ex) { log.Log(Level.WARNING, "Instance for " + className, ex); pi.SetSummary("InstanceError", true); return(pi); } // Start Process Trx trx = Trx.Get("ServerPrc"); try { bool ok = process.StartProcess(ctx, pi, trx); pi = process.GetProcessInfo(); trx.Commit(); trx.Close(); } catch (Exception ex1) { trx.Rollback(); trx.Close(); pi.SetSummary("ProcessError=>" + ex1.Message, true); return(pi); } return(pi); }
protected override void DoWork() { m_summary = new StringBuilder(m_model.ToString()) .Append(" - "); MProcess process = m_model.GetProcess(); // try { // Explicitly set Environment Ctx ctx = m_model.GetCtx(); ctx.SetAD_Client_ID(m_model.GetAD_Client_ID()); ctx.SetContext("AD_Client_ID", m_model.GetAD_Client_ID()); ctx.SetAD_Org_ID(m_model.GetAD_Org_ID()); ctx.SetContext("AD_Org_ID", m_model.GetAD_Org_ID()); ctx.SetAD_User_ID(m_model.GetUpdatedBy()); ctx.SetContext("AD_User_ID", m_model.GetUpdatedBy()); ctx.SetContext("#SalesRep_ID", m_model.GetUpdatedBy()); // m_trx = Trx.Get("Scheduler"); String result = m_model.Execute(m_trx); m_summary.Append(result); m_trx.Commit(); } catch (Exception e) { if (m_trx != null) { m_trx.Rollback(); } log.Log(Level.WARNING, process.ToString(), e); m_summary.Append(e.ToString()); } if (m_trx != null) { m_trx.Close(); } // int no = m_model.DeleteLog(); m_summary.Append("Logs deleted=").Append(no); // MSchedulerLog pLog = new MSchedulerLog(m_model, m_summary.ToString()); pLog.SetReference("#" + (_runCount.ToString()) + " - " + TimeUtil.FormatElapsed(VAdvantage.Classes.CommonFunctions.CovertMilliToDate(_startWork))); pLog.Save(); }
/** * Delete Balances * @param AD_Client_ID client * @param C_AcctSchema_ID accounting schema 0 for all * @param dateFrom null for all or first date to delete * @param trx transaction * @param svrPrc optional server process * @return Message to be translated */ public static String DeleteBalance(int AD_Client_ID, int C_AcctSchema_ID, DateTime?dateFrom, Trx trxp, int Fact_Accumulation_ID, SvrProcess svrPrc) { Trx trx = trxp; //List<Object> param = new List<Object>(); StringBuilder sql = new StringBuilder("DELETE FROM Fact_Acct_Balance WHERE AD_Client_ID=" + AD_Client_ID); //param.add(new Integer(AD_Client_ID)); if (C_AcctSchema_ID != 0) { sql.Append(" AND C_AcctSchema_ID=" + C_AcctSchema_ID); // param.add(new Integer(C_AcctSchema_ID)); } if (dateFrom != null) { //SimpleDateFormat df = new SimpleDateFormat(); //String finalDate = df.Format(dateFrom); //sql.Append(" AND DateAcct>= TO_DATE('" + finalDate + "','DD-MM-YYYY')"); sql.Append(" AND DateAcct >= " + DB.TO_DATE(dateFrom)); } if (Fact_Accumulation_ID != 0) { sql.Append(" AND Fact_Accumulation_ID = " + Fact_Accumulation_ID); //param.add(new Integer(Fact_Accumulation_ID)); } // int no = DB.ExecuteQuery(sql.ToString(), null, trx); String msg = "@Deleted@=" + no; _log.Info("C_AcctSchema_ID=" + C_AcctSchema_ID + ",DateAcct=" + dateFrom + " #=" + no); if (svrPrc != null) { svrPrc.AddLog(0, dateFrom, new Decimal(no), "Deleted"); } trx.Commit(); // return(msg); }
protected override string DoIt() { string status = "OK"; string baseCurrency = DB.ExecuteScalar("Select ISO_Code from C_Currency Where C_Currency_ID=" + baseCurrencyID).ToString(); string currencySourceName = DB.ExecuteScalar("Select url from C_CurrencySource Where C_CurrencySource_ID=" + C_CurrencySource_ID).ToString(); string myCurrency = ""; int myCurrencyID = 0; string sql = @"SELECT ISO_Code,C_Currency_ID FROM C_Currency WHERE IsActive='Y' AND ISMYCURRENCY='Y'"; DataSet ds = DB.ExecuteDataset(sql); Trx trx = Trx.Get("CreateConVersionEnties"); try { if (ds != null) { String URL = "http://localhost/CloudService55/AccountService.asmx"; //String CloudURL = "http://cloudservice.viennaadvantage.com/AccountService.asmx"; BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None) { CloseTimeout = new TimeSpan(00, 20, 00), SendTimeout = new TimeSpan(00, 20, 00), OpenTimeout = new TimeSpan(00, 20, 00), ReceiveTimeout = new TimeSpan(00, 20, 00), MaxReceivedMessageSize = int.MaxValue, MaxBufferSize = int.MaxValue }; int defaultconversionType = 0; try { defaultconversionType = Convert.ToInt32(DB.ExecuteScalar("select c_conversiontype_id from c_conversiontype where isdefault='Y' and isactive='Y'")); } catch { } MConversionRate conversion = null; Decimal rate1 = 0; Decimal rate2 = 0; Decimal one = new Decimal(1.0); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { myCurrency = ds.Tables[0].Rows[i]["ISO_Code"].ToString(); myCurrencyID = Convert.ToInt32(ds.Tables[0].Rows[i]["C_Currency_ID"]); var client = new ModelLibrary.AcctService.AccountServiceSoapClient(binding, new EndpointAddress(URL)); if (!String.IsNullOrEmpty(myCurrency) && !String.IsNullOrEmpty(baseCurrency) && !String.IsNullOrEmpty(currencySourceName)) { string result = client.GetConvertedCurrencyValue(baseCurrency, myCurrency, currencySourceName, KEY); if (!String.IsNullOrEmpty(result)) { conversion = new MConversionRate(GetCtx(), 0, trx); conversion.SetAD_Org_ID(0); conversion.SetAD_Client_ID(GetCtx().GetAD_Client_ID()); conversion.SetValidFrom(DateTime.Now); conversion.SetValidTo(DateTime.Now); conversion.SetC_ConversionType_ID(defaultconversionType); conversion.SetC_Currency_ID(myCurrencyID); conversion.SetC_Currency_To_ID(baseCurrencyID); //conversion.SetC_Currency_To_ID(); rate1 = Convert.ToDecimal(result); rate2 = Utility.Env.ZERO; one = new Decimal(1.0); if (System.Convert.ToDouble(rate1) != 0.0) // no divide by zero { rate2 = Decimal.Round(Decimal.Divide(one, rate1), 12); // MidpointRounding.AwayFromZero); } conversion.SetMultiplyRate(rate1); conversion.SetDivideRate(rate2); if (!conversion.Save(trx)) { status = "ConversionRateNotsaved"; } } result = client.GetConvertedCurrencyValue(myCurrency, baseCurrency, currencySourceName, KEY); if (!String.IsNullOrEmpty(result)) { conversion = new MConversionRate(GetCtx(), 0, trx); conversion.SetAD_Org_ID(0); conversion.SetAD_Client_ID(GetCtx().GetAD_Client_ID()); conversion.SetValidFrom(DateTime.Now); conversion.SetValidTo(DateTime.Now); conversion.SetC_ConversionType_ID(defaultconversionType); conversion.SetC_Currency_ID(baseCurrencyID); conversion.SetC_Currency_To_ID(myCurrencyID); //conversion.SetC_Currency_To_ID(); rate1 = Convert.ToDecimal(result); rate2 = Utility.Env.ZERO; one = new Decimal(1.0); if (System.Convert.ToDouble(rate1) != 0.0) // no divide by zero { rate2 = Decimal.Round(Decimal.Divide(one, rate1), 12); // MidpointRounding.AwayFromZero); } conversion.SetMultiplyRate(rate1); conversion.SetDivideRate(rate2); if (!conversion.Save(trx)) { status = "ConversionRateNotsaved"; } } } } } } catch (Exception ex) { status = ex.Message; } if (status.Equals("OK")) { trx.Commit(); } else { trx.Rollback(); } trx.Close(); return(status); }
protected override string DoIt() { string status = "OK"; Trx trx = Trx.Get("CreateCalYearPeriod"); StringBuilder sql = new StringBuilder(); //GetTenantInfo sql.Append(@"SELECT periodstartfrommonth, periodstartfromday, periodendMonth, periodendsAtDay, period_openhistory, period_openfuture FROM c_acctschema WHERE IsActive='Y' AND IsActive='Y' AND AD_Client_ID=" + GetCtx().GetAD_Client_ID()); DataSet ds = DB.ExecuteDataset(sql.ToString(), null); if (ds == null || ds.Tables[0].Rows.Count == 0) { return("SettingsNotFound"); } try { try { MonthFrom = Convert.ToInt32(ds.Tables[0].Rows[0]["periodstartfrommonth"]); } catch { } try { MonthTo = Convert.ToInt32(ds.Tables[0].Rows[0]["periodendMonth"]); } catch { } //try //{ // EntireYear = ds.Tables[0].Rows[0]["periodendMonth"].ToString().Equals("Y") ? 'Y' : 'N'; //} //catch { } try { DateFrom = Convert.ToInt32(ds.Tables[0].Rows[0]["periodstartfromday"]); } catch { } try { DateTo = Convert.ToInt32(ds.Tables[0].Rows[0]["periodendsAtDay"]); } catch { } //try //{ // daysPast = Convert.ToInt32(ds.Tables[0].Rows[0]["period_openhistory"]); //} //catch { } //try //{ // dayFuture = Convert.ToInt32(ds.Tables[0].Rows[0]["period_openfuture"]); //} //catch { } } catch { } string YearName = ""; bool isNextYear = false; if (MonthFrom < MonthTo) { YearName = DateTime.Now.Year.ToString(); } else { YearName = DateTime.Now.Year.ToString() + "-" + (DateTime.Now.Year + 1).ToString(); isNextYear = true; } sql.Clear(); sql.Append(@"SELECT C_Calendar_ID FROM C_Calendar WHERE ISACTIVE='Y' AND AD_CLIENT_ID=" + GetCtx().GetAD_Client_ID() + @" AND AD_ORG_ID=(SELECT AD_ORG_ID FROM AD_ORG WHERE NAME ='*' )"); int calendarID = 0; try { calendarID = Convert.ToInt32(DB.ExecuteScalar(sql.ToString())); } catch { } if (calendarID > 0) { sql.Clear(); sql.Append(@"SELECT C_YEAR_ID FROM C_YEAR WHERE ISACTIVE='Y' AND FiscalYear='" + YearName + "' AND C_CALENDAR_ID=" + calendarID); int yearID = 0; try { yearID = Convert.ToInt32(DB.ExecuteScalar(sql.ToString())); } catch { } MYear year = new MYear(GetCtx(), yearID, trx); year.SetC_Calendar_ID(calendarID); year.SetFiscalYear(YearName); year.SetIsActive(true); year.SetAD_Org_ID(0); if (!year.Save(trx)) { status = "YearNotSaved"; } if (!isNextYear) { for (int month = MonthFrom; month <= MonthTo; month++) { DateTime?start = null; if (month == MonthFrom) { start = new DateTime(DateTime.Now.Year, month, DateFrom).Date; } else { start = new DateTime(DateTime.Now.Year, month, 1).Date; } String name = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month) + "-" + YearName; // int day = 0; if (month == MonthTo) { day = DateTo;//TimeUtil.GetMonthLastDay(new DateTime(DateTime.Now.Year, month, DateTo)).Day; } else { day = TimeUtil.GetMonthLastDay(new DateTime(DateTime.Now.Year, month, 1)).Day; } DateTime end = new DateTime(DateTime.Now.Year, month, day).Date; // MPeriod period = new MPeriod(year, month, name, start, end); if (!period.Save(trx)) // Creates Period Control { status = "PeriodNotSaved"; } //if (EntireYear.Equals('Y'))//open Period for Entire Year //{ // if (period.Get_ID() == 0) // { // continue; // } // if (!OpenPeriod(period, trx)) // { // status = "PeriodNotOpened"; // } //} //else //{ // if (month == DateTime.Now.Month) // { // if (period.Get_ID() == 0) // { // continue; // } // if (!OpenPeriod(period, trx)) // { // status = "PeriodNotOpened"; // } // } //} } } else { for (int month = MonthFrom; month < 13; month++) { DateTime?start = null; if (month == MonthFrom) { start = new DateTime(DateTime.Now.Year, month, DateFrom).Date; } else { start = new DateTime(DateTime.Now.Year, month, 1).Date; } String name = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month) + "-" + DateTime.Now.Year.ToString(); // int day = 0; if (month == MonthTo) { day = DateTo;//TimeUtil.GetMonthLastDay(new DateTime(DateTime.Now.Year, month, DateTo)).Day; } else { day = TimeUtil.GetMonthLastDay(new DateTime(DateTime.Now.Year, month, 1)).Day; } DateTime end = new DateTime(DateTime.Now.Year, month, day).Date; // MPeriod period = new MPeriod(year, month, name, start, end); if (!period.Save(trx)) // Creates Period Control { status = "PeriodNotSaved"; } //if (EntireYear.Equals('Y'))//open Period for Entire Year //{ // if (!OpenPeriod(period, trx)) // { // status = "PeriodNotOpened"; // } //} //else //{ // if (month == DateTime.Now.Month) // { // if (period.Get_ID() == 0) // { // continue; // } // if (!OpenPeriod(period, trx)) // { // status = "PeriodNotOpened"; // } // } //} } for (int month = 1; month <= MonthTo; month++) { DateTime?start = null; if (month == MonthFrom) { start = new DateTime(DateTime.Now.Year + 1, month, DateFrom).Date; } else { start = new DateTime(DateTime.Now.Year + 1, month, 1).Date; } String name = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month) + "-" + (DateTime.Now.Year + 1).ToString(); // int day = 0; if (month == MonthTo) { day = DateTo;// TimeUtil.GetMonthLastDay(new DateTime(DateTime.Now.Year, month, DateTo)).Day; } else { day = TimeUtil.GetMonthLastDay(new DateTime(DateTime.Now.Year + 1, month, 1)).Day; } DateTime end = new DateTime(DateTime.Now.Year + 1, month, day).Date; // MPeriod period = new MPeriod(year, month, name, start, end); if (!period.Save(trx)) // Creates Period Control { status = "PeriodNotSaved"; } //if (EntireYear.Equals('Y'))//open Period for Entire Year //{ // if (period.Get_ID() == 0) // { // continue; // } // if (!OpenPeriod(period, trx)) // { // status = "PeriodNotOpened"; // } //} //else //{ // if (month == DateTime.Now.Month) // { // if (period.Get_ID() == 0) // { // continue; // } // if (!OpenPeriod(period, trx)) // { // status = "PeriodNotOpened"; // } // } //} } } } //Open Pereiod for specified Past Days // if (daysPast > 0) // { // DateTime PeriodEndDate = new DateTime(DateTime.Now.Year, MonthFrom, DateFrom); // DateTime from = PeriodEndDate.AddDays(-daysPast); // sql.Clear(); // sql.Append(@" SELECT C_Period_ID // FROM C_period // WHERE to_date(startdate,'dd-MM-yyyy') BETWEEN to_date('"+from+@"','dd-MM-yyyy') AND to_date('"+PeriodEndDate+@"','dd-MM-yyyy') // or to_date(enddate,'dd-MM-yyyy') BETWEEN to_date('" + from + @"','dd-MM-yyyy') AND to_date('" + PeriodEndDate + @"','dd-MM-yyyy')"); // ds=null; // ds=new DataSet(); // ds=DB.ExecuteDataset(sql.ToString()); // MPeriod period=null; // if (ds != null) // { // for (int i = 0; i < ds.Tables[0].Rows.Count; i++) // { // int periodID = Convert.ToInt32(ds.Tables[0].Rows[i][0]); // period = new MPeriod(GetCtx(), periodID, trx); // if (!OpenPeriod(period, trx)) // { // status = "PeriodNotOpened"; // } // } // } // } //Open Pereiod for specified Future Days // if (dayFuture > 0) // { // DateTime from=DateTime.Now; // if (isNextYear) // { // from = new DateTime(DateTime.Now.Year + 1, MonthTo, DateTo); // } // else // { // from = new DateTime(DateTime.Now.Year , MonthTo, DateTo); // } // DateTime PeriodEndDate = from.AddDays(dayFuture); // sql.Clear(); // sql.Append(@" SELECT C_Period_ID // FROM C_period // WHERE to_date(startdate,'dd-MM-yyyy') BETWEEN to_date('" + from + @"','dd-MM-yyyy') AND to_date('" + PeriodEndDate + @"','dd-MM-yyyy') // or to_date(enddate,'dd-MM-yyyy') BETWEEN to_date('" + from + @"','dd-MM-yyyy') AND to_date('" + PeriodEndDate + @"','dd-MM-yyyy')"); // ds = null; // ds = new DataSet(); // ds = DB.ExecuteDataset(sql.ToString()); // MPeriod period = null; // if (ds != null) // { // for (int i = 0; i < ds.Tables[0].Rows.Count; i++) // { // int periodID = Convert.ToInt32(ds.Tables[0].Rows[i][0]); // period = new MPeriod(GetCtx(), periodID, trx); // if (!OpenPeriod(period, trx)) // { // status = "PeriodNotOpened"; // } // } // } // } if (status == "OK") { trx.Commit(); } else { trx.Rollback(); } trx.Close(); return(status); }
public string[] InsertDimensionLine(Ctx ctx, int RecordId, decimal TotalAmount, decimal LineAmount, int[] acctSchemaID, string elementTypeID, int dimensionValue, int elementID, int oldDimensionName) { string Sql = ""; int DimAcctTypeId; int dimAmtLineId; string[] LineAmountID = new string[2]; string lineID = ""; bool error = false; Trx trx = Trx.Get("trxDim" + DateTime.Now.Millisecond); try { foreach (int acct in acctSchemaID) { X_C_DimAmt objDimAmt = new X_C_DimAmt(ctx, RecordId, trx); // if (objDimAmt.GetAmount() <= TotalAmount) // { if (CheckUpdateMaxAmount(RecordId, TotalAmount, acctSchemaID, LineAmount)) { objDimAmt.SetAmount(TotalAmount); //objDimAmt.SetAD_Table_ID(AD_TableId); // objDimAmt.SetRecord_ID(AD_RecordID); if (!objDimAmt.Save(trx)) { error = true; goto ErrorCheck; } } // } LineAmountID[0] = Convert.ToString(objDimAmt.GetC_DimAmt_ID()); RecordId = objDimAmt.GetC_DimAmt_ID(); if (acct != -1) { // RecordId = objDimAmt.GetC_DimAmt_ID(); Sql = "select nvl(c_dimamtaccttype_ID,0) from c_dimamtaccttype where c_dimamt_id=" + RecordId + " and c_acctschema_ID=" + acct + ""; DimAcctTypeId = Convert.ToInt32(DB.ExecuteScalar(Sql)); Sql = "select nvl((sum(cd.amount)),0) as Amount from c_dimamtline cd inner join c_dimamtaccttype ct on cd.c_dimamt_id=ct.c_dimamt_id " + " and cd.c_dimamtaccttype_id=ct.c_dimamtaccttype_id " + " where cd.c_dimamt_id=" + RecordId + " and ct.c_dimamtaccttype_id=" + DimAcctTypeId + ""; decimal TotoalDimAmount = Convert.ToDecimal(DB.ExecuteScalar(Sql)); if (LineAmount != -1) { TotoalDimAmount += LineAmount; } X_C_DimAmtAcctType objDimAcctType = new X_C_DimAmtAcctType(ctx, DimAcctTypeId, trx); objDimAcctType.SetC_DimAmt_ID(objDimAmt.GetC_DimAmt_ID()); if (LineAmount != -1) { objDimAcctType.SetC_AcctSchema_ID(acct); objDimAcctType.SetElementType(elementTypeID); } if (LineAmount != -1 || TotoalDimAmount != 0) { objDimAcctType.SetTotalDimLineAmout(TotoalDimAmount); if (!objDimAcctType.Save(trx)) { error = true; goto ErrorCheck; } } if (LineAmount != -1) { Sql = "select nvl(c_dimamtline_id,0) from c_dimamtline where c_Dimamt_ID=" + RecordId + " and c_dimamtaccttype_id=" + objDimAcctType.GetC_DimAmtAcctType_ID() + ""; if (elementTypeID == "AC") { Sql += " and c_elementvalue_id=" + oldDimensionName; }//Account else if (elementTypeID == "AY") { Sql += " and c_activity_id=" + oldDimensionName; } //Activity else if (elementTypeID == "BP") { Sql += " and c_BPartner_ID=" + oldDimensionName; } //BPartner else if (elementTypeID == "LF" || elementTypeID == "LT") { Sql += " and c_location_ID=" + oldDimensionName; } //Location From//Location To else if (elementTypeID == "MC") { Sql += " and c_Campaign_ID=" + oldDimensionName; } //Campaign else if (elementTypeID == "OO" || elementTypeID == "OT") { Sql += " and Org_ID=" + oldDimensionName; } //Organization//Org Trx else if (elementTypeID == "PJ") { Sql += " and c_Project_id=" + oldDimensionName; } //Project else if (elementTypeID == "PR") { Sql += " and M_Product_Id=" + oldDimensionName; } //Product else if (elementTypeID == "SR") { Sql += " and c_SalesRegion_Id=" + oldDimensionName; } //Sales Region else if (elementTypeID == "U1" || elementTypeID == "U2") { Sql += " and c_elementvalue_id=" + oldDimensionName; }//User List 1//User List 2 else if (elementTypeID == "X1" || elementTypeID == "X2" || elementTypeID == "X3" || elementTypeID == "X4" || elementTypeID == "X5" || elementTypeID == "X6" || elementTypeID == "X7" || elementTypeID == "X8" || elementTypeID == "X9") { Sql += " and AD_Column_ID=" + oldDimensionName; } //User Element 1 to User Element 9 dimAmtLineId = Convert.ToInt32(DB.ExecuteScalar(Sql)); X_C_DimAmtLine objDimAmtLine = new X_C_DimAmtLine(ctx, dimAmtLineId, trx); if (dimAmtLineId != 0) { objDimAcctType.SetTotalDimLineAmout(objDimAcctType.GetTotalDimLineAmout() - objDimAmtLine.GetAmount()); if (!objDimAcctType.Save(trx)) { error = true; goto ErrorCheck; } } objDimAmtLine.SetC_DimAmt_ID(objDimAmt.GetC_DimAmt_ID()); objDimAmtLine.SetC_DimAmtAcctType_ID(objDimAcctType.GetC_DimAmtAcctType_ID()); objDimAmtLine.SetAmount(LineAmount); if (elementTypeID == "AC") { objDimAmtLine.SetC_Element_ID(elementID); objDimAmtLine.SetC_ElementValue_ID(dimensionValue); }//Account else if (elementTypeID == "AY") { objDimAmtLine.SetC_Activity_ID(dimensionValue); } //Activity else if (elementTypeID == "BP") { objDimAmtLine.SetC_BPartner_ID(dimensionValue); } //BPartner else if (elementTypeID == "LF" || elementTypeID == "LT") { objDimAmtLine.SetC_Location_ID(dimensionValue); } //Location From//Location To else if (elementTypeID == "MC") { objDimAmtLine.SetC_Campaign_ID(dimensionValue); } //Campaign else if (elementTypeID == "OO" || elementTypeID == "OT") { objDimAmtLine.SetOrg_ID(dimensionValue); } //Organization//Org Trx else if (elementTypeID == "PJ") { objDimAmtLine.SetC_Project_ID(dimensionValue); } //Project else if (elementTypeID == "PR") { objDimAmtLine.SetM_Product_ID(dimensionValue); } //Product else if (elementTypeID == "SA") { } //Sub Account else if (elementTypeID == "SR") { objDimAmtLine.SetC_SalesRegion_ID(dimensionValue); } //Sales Region else if (elementTypeID == "U1" || elementTypeID == "U2") { objDimAmtLine.SetC_Element_ID(elementID); objDimAmtLine.SetC_ElementValue_ID(dimensionValue); }//User List 1//User List 2 else if (elementTypeID == "X1" || elementTypeID == "X2" || elementTypeID == "X3" || elementTypeID == "X4" || elementTypeID == "X5" || elementTypeID == "X6" || elementTypeID == "X7" || elementTypeID == "X8" || elementTypeID == "X9") { objDimAmtLine.SetAD_Column_ID(dimensionValue); } //User Element 1 to User Element 9 if (!objDimAmtLine.Save(trx)) { error = true; goto ErrorCheck; } if (lineID == "") { lineID += Convert.ToString(objDimAmtLine.GetC_DimAmtLine_ID()); } else { lineID += "," + Convert.ToString(objDimAmtLine.GetC_DimAmtLine_ID()); } } } else { break; } ErrorCheck: if (error) { break; } } } catch (Exception e) { error = true; } finally { if (error) { LineAmountID[0] = ""; LineAmountID[1] = ""; trx.Rollback(); log.Warning("Some error occured while saving Dimension"); } else { LineAmountID[1] = lineID; trx.Commit(); } } return(LineAmountID); }
/// <summary> /// Save Data /// </summary> public void SavePaymentData(List <Dictionary <string, string> > rowsPayment, List <Dictionary <string, string> > rowsCash, List <Dictionary <string, string> > rowsInvoice, string currency, bool isCash, int _C_BPartner_ID, int _windowNo, string payment, DateTime DateTrx, string applied, string discount, string writeOff, string open) { // fixed fields int AD_Client_ID = ctx.GetContextAsInt(_windowNo, "AD_Client_ID"); int AD_Org_ID = ctx.GetContextAsInt(_windowNo, "AD_Org_ID"); int C_BPartner_ID = _C_BPartner_ID; int C_Order_ID = 0; int C_CashLine_ID = 0; //DateTime? DateTrx = Util.GetValueOfDateTime(vdtpDateField.GetValue()); int C_Currency_ID = Convert.ToInt32(currency); // if (AD_Org_ID == 0) { //Classes.ShowMessage.Error("Org0NotAllowed", null); return; } // // log.Config("Client=" + AD_Client_ID + ", Org=" + AD_Org_ID // + ", BPartner=" + C_BPartner_ID + ", Date=" + DateTrx); Trx trx = Trx.Get(Trx.CreateTrxName("AL"), true); /** * Generation of allocations: amount/discount/writeOff * - if there is one payment -- one line per invoice is generated * with both the Invoice and Payment reference * Pay=80 Inv=100 Disc=10 WOff=10 => 80/10/10 Pay#1 Inv#1 * or * Pay=160 Inv=100 Disc=10 WOff=10 => 80/10/10 Pay#1 Inv#1 * Pay=160 Inv=100 Disc=10 WOff=10 => 80/10/10 Pay#1 Inv#2 * * - if there are multiple payment lines -- the amounts are allocated * starting with the first payment and payment * Pay=60 Inv=100 Disc=10 WOff=10 => 60/10/10 Pay#1 Inv#1 * Pay=100 Inv=100 Disc=10 WOff=10 => 20/0/0 Pay#2 Inv#1 * Pay=100 Inv=100 Disc=10 WOff=10 => 80/10/10 Pay#2 Inv#2 * * - if you apply a credit memo to an invoice * Inv=10 Disc=0 WOff=0 => 10/0/0 Inv#1 * Inv=-10 Disc=0 WOff=0 => -10/0/0 Inv#2 * * - if you want to write off a (partial) invoice without applying, * enter zero in applied * Inv=10 Disc=1 WOff=9 => 0/1/9 Inv#1 * Issues * - you cannot write-off a payment */ // Payment - Loop and Add them to paymentList/amountList try { #region Payment-Loop //int pRows = vdgvPayment.ItemsSource.OfType<object>().Count(); // IList rowsPayment = vdgvPayment.ItemsSource as IList; List <int> paymentList = new List <int>(rowsPayment.Count); List <Decimal> amountList = new List <Decimal>(rowsPayment.Count); Decimal paymentAppliedAmt = Env.ZERO; for (int i = 0; i < rowsPayment.Count; i++) { // Payment line is selected // bool boolValue = false; //if (boolValue) { //KeyNamePair pp = (KeyNamePair)vdgvPayment.Rows[i].Cells[2].Value; // KeyNamePair pp = (KeyNamePair)(((BindableObject)rowsPayment[i]).GetValue(2)); // Value // Payment variables int C_Payment_ID = Util.GetValueOfInt(rowsPayment[i]["cpaymentid"]); paymentList.Add(C_Payment_ID); // // Decimal PaymentAmt = Util.GetValueOfDecimal(vdgvPayment.Rows[i].Cells[_payment].Value); // Applied Payment Decimal PaymentAmt = Util.GetValueOfDecimal(rowsPayment[i][payment]); // Applied Payment amountList.Add(PaymentAmt); // paymentAppliedAmt = Decimal.Add(paymentAppliedAmt, PaymentAmt); // // log.Fine("C_Payment_ID=" + C_Payment_ID // + " - PaymentAmt=" + PaymentAmt); // + " * " + Multiplier + " = " + PaymentAmtAbs); MPayment pay1 = new MPayment(ctx, C_Payment_ID, trx); } } //log.Config("Number of Payments=" + paymentList.Count + " - Total=" + paymentAppliedAmt); #endregion // Invoices - Loop and generate alloctions #region Invoice-Loop with allocation // int iRows = vdgvInvoice.ItemsSource.OfType<object>().Count(); // IList rowsInvoice=vdgvInvoice.ItemsSource as IList; Decimal totalAppliedAmt = Env.ZERO; // Create Allocation - but don't save yet MAllocationHdr alloc = new MAllocationHdr(ctx, true, // manual DateTrx, C_Currency_ID, ctx.GetContext("#AD_User_Name"), trx); alloc.SetAD_Org_ID(AD_Org_ID); // For all invoices int invoiceLines = 0; for (int i = 0; i < rowsInvoice.Count; i++) { // Invoice line is selected //if (boolValue) { invoiceLines++; // KeyNamePair pp = (KeyNamePair)vdgvInvoice.Rows[i].Cells[2].Value; // Value // KeyNamePair pp = (KeyNamePair)(((BindableObject)rowsPayment[i]).GetValue(2)); // Value // Invoice variables int C_Invoice_ID = Util.GetValueOfInt(rowsInvoice[i]["cinvoiceid"]); // Decimal AppliedAmt = Util.GetValueOfDecimal(vdgvInvoice.Rows[i].Cells[_applied].Value); Decimal AppliedAmt = Util.GetValueOfDecimal(rowsInvoice[i][applied]); // semi-fixed fields (reset after first invoice) // Decimal DiscountAmt = Util.GetValueOfDecimal(vdgvInvoice.Rows[i].Cells[_discount].Value); // Decimal WriteOffAmt = Util.GetValueOfDecimal(vdgvInvoice.Rows[i].Cells[_writeOff].Value); Decimal DiscountAmt = Util.GetValueOfDecimal(rowsInvoice[i][discount]); Decimal WriteOffAmt = Util.GetValueOfDecimal(rowsInvoice[i][writeOff]); // OverUnderAmt needs to be in Allocation Currency // Decimal OverUnderAmt = Decimal.Subtract(Util.GetValueOfDecimal(vdgvInvoice.Rows[i].Cells[_open].Value), // Decimal.Subtract(AppliedAmt, Decimal.Subtract(DiscountAmt, WriteOffAmt))); Decimal OverUnderAmt = Decimal.Subtract(Util.GetValueOfDecimal(rowsInvoice[i][open]), Decimal.Subtract(AppliedAmt, Decimal.Subtract(DiscountAmt, WriteOffAmt))); // log.Config("Invoice #" + i + " - AppliedAmt=" + AppliedAmt);// + " -> " + AppliedAbs); //Payment Settelment********** // loop through all payments until invoice applied int noPayments = 0; for (int j = 0; j < paymentList.Count && Env.Signum(AppliedAmt) != 0; j++) { int C_Payment_ID = Util.GetValueOfInt(paymentList[j]); Decimal PaymentAmt = Util.GetValueOfDecimal(amountList[j]); if (Env.Signum(PaymentAmt) != 0) { // log.Config(".. with payment #" + j + ", Amt=" + PaymentAmt); noPayments++; // use Invoice Applied Amt Decimal amount = Env.ZERO; if ((Math.Abs(AppliedAmt)).CompareTo(Math.Abs(PaymentAmt)) > 0) { amount = PaymentAmt; } else { amount = AppliedAmt; } //log.Fine("C_Payment_ID=" + C_Payment_ID + ", C_Invoice_ID=" + C_Invoice_ID // + ", Amount=" + amount + ", Discount=" + DiscountAmt + ", WriteOff=" + WriteOffAmt); // Allocation Header if (alloc.Get_ID() == 0 && !alloc.Save()) { // log.Log(Level.SEVERE, "Allocation not created"); trx.Rollback(); trx.Close(); return; } // Allocation Line MAllocationLine aLine = new MAllocationLine(alloc, amount, DiscountAmt, WriteOffAmt, OverUnderAmt); aLine.SetDocInfo(C_BPartner_ID, C_Order_ID, C_Invoice_ID); //aLine.SetPaymentInfo(C_Payment_ID, C_CashLine_ID); aLine.SetPaymentInfo(C_Payment_ID, 0);//cashline for payment allocation is zero if (!aLine.Save()) { // log.Log(Level.SEVERE, "Allocation Line not written - Invoice=" + C_Invoice_ID); } // Apply Discounts and WriteOff only first time DiscountAmt = Env.ZERO; WriteOffAmt = Env.ZERO; // subtract amount from Payment/Invoice AppliedAmt = Decimal.Subtract(AppliedAmt, amount); //AppliedAmt = Decimal.Subtract(PaymentAmt, AppliedAmt); PaymentAmt = Decimal.Subtract(PaymentAmt, amount); //log.Fine("Allocation Amount=" + amount + " - Remaining Applied=" + AppliedAmt + ", Payment=" + PaymentAmt); //amountList.set(j, PaymentAmt); // update amountList[j] = PaymentAmt; // update//set } // for all applied amounts MPayment pay1 = new MPayment(ctx, C_Payment_ID, trx); } // loop through payments for invoice // No Payments allocated and none existing (e.g. Inv/CM) if (noPayments == 0 && paymentList.Count == 0) { int C_Payment_ID = 0; // log.Config(" ... no payment - TotalApplied=" + totalAppliedAmt); // Create Allocation // log.Fine("C_Payment_ID=" + C_Payment_ID + ", C_Invoice_ID=" + C_Invoice_ID // + ", Amount=" + AppliedAmt + ", Discount=" + DiscountAmt + ", WriteOff=" + WriteOffAmt); // Allocation Header if (alloc.Get_ID() == 0 && !alloc.Save()) { //log.Log(Level.SEVERE, "Allocation not created"); trx.Rollback(); trx.Close(); return; } // Allocation Line MAllocationLine aLine = new MAllocationLine(alloc, AppliedAmt, DiscountAmt, WriteOffAmt, OverUnderAmt); aLine.SetDocInfo(C_BPartner_ID, C_Order_ID, C_Invoice_ID); //aLine.SetPaymentInfo(C_Payment_ID, C_CashLine_ID); aLine.SetPaymentInfo(C_Payment_ID, 0); if (!aLine.Save(trx)) { //Log(Level.SEVERE, "Allocation Line not written - Invoice=" + C_Invoice_ID); } // log.Fine("Allocation Amount=" + AppliedAmt); MPayment pay1 = new MPayment(ctx, C_Payment_ID, trx); } totalAppliedAmt = Decimal.Add(totalAppliedAmt, AppliedAmt); // log.Config("TotalRemaining=" + totalAppliedAmt); } // invoice selected } // invoice loop #endregion // Only Payments and total of 0 (e.g. Payment/Reversal) #region Reversal Payments if (invoiceLines == 0 && paymentList.Count > 0 && Env.Signum(paymentAppliedAmt) == 0) { for (int i = 0; i < paymentList.Count; i++) { int C_Payment_ID = Util.GetValueOfInt(paymentList[i]); Decimal PaymentAmt = Util.GetValueOfDecimal(amountList[i]); // log.Fine("Payment=" + C_Payment_ID // + ", Amount=" + PaymentAmt);// + ", Abs=" + PaymentAbs); // Allocation Header if (alloc.Get_ID() == 0 && !alloc.Save()) { // log.Log(Level.SEVERE, "Allocation not created"); trx.Rollback(); trx.Close(); return; } // Allocation Line MAllocationLine aLine = new MAllocationLine(alloc, PaymentAmt, Env.ZERO, Env.ZERO, Env.ZERO); aLine.SetDocInfo(C_BPartner_ID, 0, 0); aLine.SetPaymentInfo(C_Payment_ID, 0); if (!aLine.Save(trx)) { // log.Log(Level.SEVERE, "Allocation Line not saved - Payment=" + C_Payment_ID); } MPayment pay1 = new MPayment(ctx, C_Payment_ID, trx); } } // onlyPayments #endregion if (Env.Signum(totalAppliedAmt) != 0) { //log.Log(Level.SEVERE, "Remaining TotalAppliedAmt=" + totalAppliedAmt); } // Should start WF if (alloc.Get_ID() != 0) { alloc.ProcessIt(DocActionVariables.ACTION_COMPLETE); alloc.Save(); } // Test/Set IsPaid for Invoice - requires that allocation is posted #region Set Invoice IsPaid for (int i = 0; i < rowsInvoice.Count; i++) { // Invoice line is selected // if (boolValue) { //KeyNamePair pp = (KeyNamePair)vdgvInvoice.Rows[i].Cells[2].Value; // Value // KeyNamePair pp = (KeyNamePair)((BindableObject)rowsInvoice[i]).GetValue(2); // Value // Invoice variables int C_Invoice_ID = Util.GetValueOfInt(rowsInvoice[i]["cinvoiceid"]); String sql = "SELECT invoiceOpen(C_Invoice_ID, 0) " + "FROM C_Invoice WHERE C_Invoice_ID=@param1"; Decimal opens = Util.GetValueOfDecimal(DB.GetSQLValueBD(trx, sql, C_Invoice_ID)); if (open != null && Env.Signum(opens) == 0) { sql = "UPDATE C_Invoice SET IsPaid='Y' " + "WHERE C_Invoice_ID=" + C_Invoice_ID; int no = DB.ExecuteQuery(sql, null, trx); // log.Config("Invoice #" + i + " is paid"); } else { // log.Config("Invoice #" + i + " is not paid - " + open); } } } #endregion // Test/Set Payment is fully allocated #region Set Payment Allocated if (rowsPayment.Count > 0) { for (int i = 0; i < paymentList.Count; i++) { int C_Payment_ID = Util.GetValueOfInt(paymentList[i]); MPayment pay = new MPayment(ctx, C_Payment_ID, trx); if (pay.TestAllocation()) { pay.Save(); } string sqlGetOpenPayments = "SELECT currencyConvert(ALLOCPAYMENTAVAILABLE(C_Payment_ID) ,p.C_Currency_ID ,260,p.DateTrx ,p.C_ConversionType_ID ,p.AD_Client_ID ,p.AD_Org_ID) FROM C_Payment p Where C_Payment_ID = " + C_Payment_ID; object result = DB.ExecuteScalar(sqlGetOpenPayments, null, trx); Decimal?amtPayment = 0; if (result == null || result == DBNull.Value) { amtPayment = -1; } else { amtPayment = Util.GetValueOfDecimal(result); } if (amtPayment == 0) { pay.SetIsAllocated(true); } else { pay.SetIsAllocated(false); } pay.Save(); //log.Config("Payment #" + i + (pay.IsAllocated() ? " not" : " is") // + " fully allocated"); } } #endregion paymentList.Clear(); amountList.Clear(); trx.Commit(); trx.Close(); } catch { if (trx != null) { trx.Rollback(); trx.Close(); trx = null; } } finally { if (trx != null) { trx.Rollback(); trx.Close(); trx = null; } } }
public string SaveCashData(List <Dictionary <string, string> > paymentData, List <Dictionary <string, string> > rowsCash, List <Dictionary <string, string> > rowsInvoice, string currency, bool isCash, int _C_BPartner_ID, int _windowNo, string payment, DateTime DateTrx, string applied, string discount, string writeOff, string open) { //if (_noInvoices + _noCashLines == 0) // return ""; int C_Currency_ID = Convert.ToInt32(currency); // fixed fields int AD_Client_ID = ctx.GetContextAsInt(_windowNo, "AD_Client_ID"); int AD_Org_ID = ctx.GetContextAsInt(_windowNo, "AD_Org_ID"); int C_BPartner_ID = _C_BPartner_ID; int C_Order_ID = 0; int C_CashLine_ID = 0; // if (AD_Org_ID == 0) { //Classes.ShowMessage.Error("Org0NotAllowed", null); return(""); } // // log.Config("Client=" + AD_Client_ID + ", Org=" + AD_Org_ID // + ", BPartner=" + C_BPartner_ID + ", Date=" + DateTrx); Trx trx = Trx.Get(Trx.CreateTrxName("AL"), true); /** * Generation of allocations: amount/discount/writeOff * - if there is one payment -- one line per invoice is generated * with both the Invoice and Payment reference * Pay=80 Inv=100 Disc=10 WOff=10 => 80/10/10 Pay#1 Inv#1 * or * Pay=160 Inv=100 Disc=10 WOff=10 => 80/10/10 Pay#1 Inv#1 * Pay=160 Inv=100 Disc=10 WOff=10 => 80/10/10 Pay#1 Inv#2 * * - if there are multiple payment lines -- the amounts are allocated * starting with the first payment and payment * Pay=60 Inv=100 Disc=10 WOff=10 => 60/10/10 Pay#1 Inv#1 * Pay=100 Inv=100 Disc=10 WOff=10 => 20/0/0 Pay#2 Inv#1 * Pay=100 Inv=100 Disc=10 WOff=10 => 80/10/10 Pay#2 Inv#2 * * - if you apply a credit memo to an invoice * Inv=10 Disc=0 WOff=0 => 10/0/0 Inv#1 * Inv=-10 Disc=0 WOff=0 => -10/0/0 Inv#2 * * - if you want to write off a (partial) invoice without applying, * enter zero in applied * Inv=10 Disc=1 WOff=9 => 0/1/9 Inv#1 * Issues * - you cannot write-off a payment */ // CashLines - Loop and Add them to cashList/CashAmountList #region CashLines-Loop // int cRows = vdgvCashLines.RowCount; // IList rowsCash = vdgvCashLine.ItemsSource as IList; List <int> cashList = new List <int>(rowsCash.Count); List <Decimal> CashAmtList = new List <Decimal>(rowsCash.Count); Decimal cashAppliedAmt = Env.ZERO; for (int i = 0; i < rowsCash.Count; i++) { // Payment line is selected bool boolValue = false; bool flag = false; // if (boolValue) { // Payment variables C_CashLine_ID = Util.GetValueOfInt(rowsCash[i]["ccashlineid"]); cashList.Add(C_CashLine_ID); // //Decimal PaymentAmt = Util.GetValueOfDecimal(((BindableObject)rowsCash[i]).GetValue(_payment)); // Applied Payment Decimal PaymentAmt = Util.GetValueOfDecimal(rowsCash[i][payment]); // Applied Payment CashAmtList.Add(PaymentAmt); // cashAppliedAmt = Decimal.Add(cashAppliedAmt, PaymentAmt); // // log.Fine("C_CashLine_ID=" + C_CashLine_ID // + " - PaymentAmt=" + PaymentAmt); // + " * " + Multiplier + " = " + PaymentAmtAbs); } } //log.Config("Number of Cashlines=" + cashList.Count + " - Total=" + cashAppliedAmt); #endregion // Invoices - Loop and generate alloctions #region Invoice-Loop with allocation // int iRows = vdgvInvoice.RowCount; // IList rowsInvoice = vdgvInvoice.ItemsSource as IList; Decimal totalAppliedAmt = Env.ZERO; // Create Allocation - but don't save yet MAllocationHdr alloc = new MAllocationHdr(ctx, true, // manual DateTrx, C_Currency_ID, ctx.GetContext("#AD_User_Name"), trx); alloc.SetAD_Org_ID(AD_Org_ID); // For all invoices int invoiceLines = 0; //for (int i = 0; i < rowsCash.Count; i++) for (int i = 0; i < rowsInvoice.Count; i++) { // Invoice line is selected bool boolValue = false; bool flag = false; // if (boolValue) { invoiceLines++; // Invoice variables /// int C_Invoice_ID = Util.GetValueOfInt(((BindableObject)rowsInvoice[i]).GetValue("C_INVOICE_ID")); int C_Invoice_ID = Util.GetValueOfInt(rowsInvoice[i]["cinvoiceid"]); Decimal AppliedAmt = Util.GetValueOfDecimal(rowsInvoice[i][applied]); // semi-fixed fields (reset after first invoice) Decimal DiscountAmt = Util.GetValueOfDecimal(rowsInvoice[i][discount]); Decimal WriteOffAmt = Util.GetValueOfDecimal(rowsInvoice[i][writeOff]); // OverUnderAmt needs to be in Allocation Currency Decimal OverUnderAmt = Decimal.Subtract(Util.GetValueOfDecimal(rowsInvoice[i][open]), Decimal.Subtract(AppliedAmt, Decimal.Subtract(DiscountAmt, WriteOffAmt))); //log.Config("Invoice #" + i + " - AppliedAmt=" + AppliedAmt);// + " -> " + AppliedAbs); //CashLines settelment************ // loop through all payments until invoice applied int noCashlines = 0; for (int j = 0; j < cashList.Count && Env.Signum(AppliedAmt) != 0; j++) { C_CashLine_ID = Util.GetValueOfInt(cashList[j]); Decimal PaymentAmt = Util.GetValueOfDecimal(CashAmtList[j]); if (Env.Signum(PaymentAmt) != 0) { //log.Config(".. with payment #" + j + ", Amt=" + PaymentAmt); noCashlines++; // use Invoice Applied Amt Decimal amount = AppliedAmt; //log.Fine("C_CashLine_ID=" + C_CashLine_ID + ", C_Invoice_ID=" + C_Invoice_ID // + ", Amount=" + amount + ", Discount=" + DiscountAmt + ", WriteOff=" + WriteOffAmt); // Allocation Header if (alloc.Get_ID() == 0 && !alloc.Save()) { // log.Log(Level.SEVERE, "Allocation not created"); trx.Rollback(); trx.Close(); return(""); } // Allocation Line MAllocationLine aLine = new MAllocationLine(alloc, amount, DiscountAmt, WriteOffAmt, OverUnderAmt); aLine.SetDocInfo(C_BPartner_ID, C_Order_ID, C_Invoice_ID); aLine.SetPaymentInfo(0, C_CashLine_ID);//payment for payment allocation is zero if (!aLine.Save()) { // log.Log(Level.SEVERE, "Allocation Line not written - Invoice=" + C_Invoice_ID); // Apply Discounts and WriteOff only first time DiscountAmt = Env.ZERO; } WriteOffAmt = Env.ZERO; // subtract amount from Payment/Invoice AppliedAmt = Decimal.Subtract(AppliedAmt, amount); //AppliedAmt = Decimal.Subtract(PaymentAmt, AppliedAmt); PaymentAmt = Decimal.Subtract(PaymentAmt, amount); //log.Fine("Allocation Amount=" + amount + " - Remaining Applied=" + AppliedAmt + ", Payment=" + PaymentAmt); //amountList.set(j, PaymentAmt); // update if (CashAmtList.Count > 0) { MCashLine cline = new MCashLine(ctx, C_CashLine_ID, null); cline.SetAmount(Decimal.Subtract(cline.GetAmount(), CashAmtList[j])); if (!cline.Save()) { // log.SaveError("AmountIsNotUpdated" + C_CashLine_ID.ToString(), ""); } CashAmtList[j] = PaymentAmt; // update//set } } // for all applied amounts } // loop through Cash for invoice(Charge) // No Cashlines allocated and none existing if (rowsCash.Count > 0) { if (noCashlines == 0 && cashList.Count == 0) { C_CashLine_ID = 0; //log.Config(" ... no CashLines - TotalApplied=" + totalAppliedAmt); // Create Allocation // log.Fine("C_CashLine_ID=" + C_CashLine_ID + ", C_Invoice_ID=" + C_Invoice_ID // + ", Amount=" + AppliedAmt + ", Discount=" + DiscountAmt + ", WriteOff=" + WriteOffAmt); // Allocation Header if (alloc.Get_ID() == 0 && !alloc.Save()) { //log.Log(Level.SEVERE, "Allocation not created"); trx.Rollback(); trx.Close(); return(""); } // Allocation Line MAllocationLine aLine = new MAllocationLine(alloc, AppliedAmt, DiscountAmt, WriteOffAmt, OverUnderAmt); aLine.SetDocInfo(C_BPartner_ID, C_Order_ID, C_Invoice_ID); aLine.SetPaymentInfo(0, C_CashLine_ID); if (!aLine.Save(trx)) { } // log.Log(Level.SEVERE, "Allocation Line not written - Invoice=" + C_Invoice_ID); //log.Fine("Allocation Amount=" + AppliedAmt); } } totalAppliedAmt = Decimal.Add(totalAppliedAmt, AppliedAmt); //log.Config("TotalRemaining=" + totalAppliedAmt); } // invoice selected } // invoice loop #endregion if (Env.Signum(totalAppliedAmt) != 0) { //log.Log(Level.SEVERE, "Remaining TotalAppliedAmt=" + totalAppliedAmt); // Should start WF if (alloc.Get_ID() != 0) { alloc.ProcessIt(DocActionVariables.ACTION_COMPLETE); alloc.Save(); } } // Test/Set IsPaid for Invoice - requires that allocation is posted #region Set Invoice IsPaid for (int i = 0; i < rowsInvoice.Count; i++) { bool boolValue = false; // Invoice line is selected bool flag = false; //Dispatcher.BeginInvoke(delegate //{ // boolValue = GetBoolValue(vdgvInvoice, i, 0); // flag = true; // SetBusy(false); //}); //while (!flag) //{ // System.Threading.Thread.Sleep(1); //} // if (boolValue) { //KeyNamePair pp = (KeyNamePair)vdgvInvoice.Rows[i].Cells[2].Value; // Value //KeyNamePair pp = (KeyNamePair)((BindableObject)rowsInvoice[i]).GetValue(2); // Value // Invoice variables int C_Invoice_ID = Util.GetValueOfInt(rowsInvoice[i]["cinvoiceid"]); String sql = "SELECT invoiceOpen(C_Invoice_ID, 0) " + "FROM C_Invoice WHERE C_Invoice_ID=@param1"; Decimal opens = Util.GetValueOfDecimal(DB.GetSQLValueBD(trx, sql, C_Invoice_ID)); if (open != null && Env.Signum(opens) == 0) { sql = "UPDATE C_Invoice SET IsPaid='Y' " + "WHERE C_Invoice_ID=" + C_Invoice_ID; int no = DB.ExecuteQuery(sql, null, trx); // log.Config("Invoice #" + i + " is paid"); } else { // log.Config("Invoice #" + i + " is not paid - " + open); } } } #endregion // Test/Set CashLine is fully allocated #region Set CashLine Allocated if (rowsCash.Count > 0) { for (int i = 0; i < cashList.Count; i++) { C_CashLine_ID = Util.GetValueOfInt(cashList[i]); MCashLine cash = new MCashLine(ctx, C_CashLine_ID, trx); if (cash.GetAmount() == 0) { cash.SetIsAllocated(true); cash.Save(); } // log.Config("Cash #" + i + (cash.IsAllocated() ? " not" : " is") // + " fully allocated"); } } #endregion cashList.Clear(); CashAmtList.Clear(); trx.Commit(); trx.Close(); return(""); }
/// <summary> /// Starts the process by calling the required class at run time. /// </summary> /// <returns>Returs ture or false on the successfull calling of the proecss</returns> private bool StartProcess() { //_trx = Trx.Get("ServerProcess", true); //log.Fine(_pi.ToString()); try { string className = _pi.GetClassName().Replace("org.compiere.process", "VAdvantage.Process"); className = className.Replace("org.compiere.wf", "VAdvantage.WF"); className = className.Replace("org.compiere.report", "VAdvantage.Report"); className = className.Replace("org.compiere.install", "VAdvantage.Install"); className = className.Replace("org.compiere.print", "VAdvantage.Print"); className = className.Replace("org.compiere.cmrp.process", "ViennaAdvantage.CMRP.Process"); className = className.Replace("org.compiere.cmfg.process", "ViennaAdvantage.CMFG.Process"); className = className.Replace("org.compiere.cwms.process", "ViennaAdvantage.CWMS.Process"); className = className.Replace("org.compiere.cm", "VAdvantage.CM"); /*Customization Process */ Type type = null; string cName = _pi.GetTitle(); type = Utility.ModuleTypeConatiner.GetClassType(className, cName); if (type == null) { //MessageBox.Show("no Type"); } if (type.IsClass) { ProcessEngine.ProcessCall oClass = (ProcessEngine.ProcessCall)Activator.CreateInstance(type); if (oClass == null) { return(false); } else { //oClass.StartProcess(_ctx, _pi, _trx); oClass.StartProcess(_ctx, _pi, _trx); } if (_trx != null) { _trx.Commit(); //log.Fine("Commit " + _trx.ToString()); _trx.Close(); } } } catch { if (_trx != null) { _trx.Rollback(); //log.Fine("Rollback " + _trx.ToString()); _trx.Close(); } _pi.SetSummary("Error starting Class " + _pi.GetClassName().Replace("org.compiere.process", "VAdvantage.Process"), true); //log.Log(Level.SEVERE, _pi.GetClassName(), ex); } return(!_pi.IsError()); }
protected override string DoIt() { tlLanguageID = GetRecord_ID(); if (tlLanguageID == 0) { return("NoLanguageFound"); } Trx trx = Trx.Get("TRLF"); StringBuilder res = new StringBuilder(); StringBuilder sql = new StringBuilder(); ////////Translate System Element sql.Clear(); sql.Append("SELECT * FROM I_TLELEMENT_trl WHERE IsContinueTranslation='Y' AND I_TLLanguage_ID=" + tlLanguageID); DataSet ds = DB.ExecuteDataset(sql.ToString()); string lang = Util.GetValueOfString(DB.ExecuteScalar("select I_TLLanguage From I_TLLanguage WHERE I_TLLAnguage_ID=" + tlLanguageID)); System.Data.SqlClient.SqlParameter[] param = null; string desc = ""; string help = ""; if (ds != null) { X_I_TLElement_Trl tlEle = null; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tlEle = new X_I_TLElement_Trl(GetCtx(), ds.Tables[0].Rows[i], null); sql.Clear(); param = new System.Data.SqlClient.SqlParameter[8]; param[0] = new System.Data.SqlClient.SqlParameter("@cname", tlEle.GetName()); if (string.IsNullOrEmpty(tlEle.GetPrintName())) { param[1] = new System.Data.SqlClient.SqlParameter("@PrintName", DBNull.Value); } else { param[1] = new System.Data.SqlClient.SqlParameter("@PrintName", tlEle.GetPrintName()); } if (string.IsNullOrEmpty(tlEle.GetDescription())) { param[2] = new System.Data.SqlClient.SqlParameter("@description", DBNull.Value); } else { param[2] = new System.Data.SqlClient.SqlParameter("@description", tlEle.GetDescription()); } help = tlEle.GetHelp(); if (string.IsNullOrEmpty(help)) { param[3] = new System.Data.SqlClient.SqlParameter("@help", DBNull.Value); } else { param[3] = new System.Data.SqlClient.SqlParameter("@help", help); } if (string.IsNullOrEmpty(tlEle.GetPO_Name())) { param[4] = new System.Data.SqlClient.SqlParameter("@POName", DBNull.Value); } else { param[4] = new System.Data.SqlClient.SqlParameter("@POName", tlEle.GetPO_Name()); } if (string.IsNullOrEmpty(tlEle.GetPO_PrintName())) { param[5] = new System.Data.SqlClient.SqlParameter("@POPrintName", DBNull.Value); } else { param[5] = new System.Data.SqlClient.SqlParameter("@POPrintName", tlEle.GetPO_PrintName()); } if (string.IsNullOrEmpty(tlEle.GetPO_Description())) { param[6] = new System.Data.SqlClient.SqlParameter("@POdesc", DBNull.Value); } else { param[6] = new System.Data.SqlClient.SqlParameter("@POdesc", tlEle.GetPO_Description()); } if (string.IsNullOrEmpty(tlEle.GetPO_Help())) { param[7] = new System.Data.SqlClient.SqlParameter("@POhelp", DBNull.Value); } else { param[7] = new System.Data.SqlClient.SqlParameter("@POhelp", tlEle.GetPO_Help()); } sql.Append(@"Update AD_ELEMENT_TRL SET Name=@cname, IsTranslated='Y', PrintName=@PrintName, Description=@description, Help=@help, PO_Name=@POName, PO_PrintName=@POPrintName, PO_Description=@POdesc, PO_Help=@POhelp WHERE AD_ELEMENT_ID=" + tlEle.GetAD_Element_ID() + " AND AD_LANGUAGE='" + lang + "'"); if (DB.ExecuteQuery(sql.ToString(), param, trx) == -1) { res.Append(tlEle.GetAD_Element_ID() + " ElementNotTranslated."); break; } tlEle.SetIsTranslated(true); tlEle.Save(trx); //} } } sql.Clear(); sql.Append("SELECT * FROM I_TLField_trl WHERE IsContinueTranslation='Y' AND I_TLLanguage_ID=" + tlLanguageID); ds = DB.ExecuteDataset(sql.ToString()); if (ds != null) { X_I_TLField_Trl tlField = null; char isCentrallyMaintained = 'N'; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tlField = new X_I_TLField_Trl(GetCtx(), ds.Tables[0].Rows[i], null); isCentrallyMaintained = 'N'; if (tlField.IsTranslateSystemElement()) { isCentrallyMaintained = 'Y'; //Translate System Element trl sql.Clear(); param = new System.Data.SqlClient.SqlParameter[2]; param[0] = new System.Data.SqlClient.SqlParameter("@cname", tlField.GetName()); param[1] = new System.Data.SqlClient.SqlParameter("@PrintName", tlField.GetName()); sql.Append(@"Update AD_ELEMENT_TRL SET Name=@cname, PRINTNAME=@PrintName, IsTranslated='Y' WHERE AD_ELEMENT_ID=" + tlField.GetAD_Element_ID() + " AND AD_LANGUAGE='" + lang + "'"); if (DB.ExecuteQuery(sql.ToString(), param, trx) == -1) { res.Append(tlField.GetAD_Element_ID() + " SystemElementNotTranslated."); break; } } //else //{ // Tarnslate Field Trl sql.Clear(); param = new System.Data.SqlClient.SqlParameter[3]; param[0] = new System.Data.SqlClient.SqlParameter("@cname", tlField.GetName()); desc = tlField.GetDescription(); if (string.IsNullOrEmpty(desc)) { param[1] = new System.Data.SqlClient.SqlParameter("@description", DBNull.Value); } else { param[1] = new System.Data.SqlClient.SqlParameter("@description", desc); } help = tlField.GetHelp(); if (string.IsNullOrEmpty(help)) { param[2] = new System.Data.SqlClient.SqlParameter("@help", DBNull.Value); } else { param[2] = new System.Data.SqlClient.SqlParameter("@help", help); } sql.Append(@"Update AD_Field_TRL SET Name=@cname, IsTranslated='Y', Description=@description, help=@help WHERE AD_Field_ID=" + tlField.GetAD_Field_ID() + " AND AD_LANGUAGE='" + lang + "'"); if (DB.ExecuteQuery(sql.ToString(), param, trx) == -1) { res.Append(tlField.GetAD_Field_ID() + " FieldNotTranslated."); break; } sql.Clear(); sql.Append("UPDATE AD_Field SET IsCentrallyMaintained='" + isCentrallyMaintained + "' WHERE AD_Field_ID=" + tlField.GetAD_Field_ID()); DB.ExecuteQuery(sql.ToString(), null, trx); tlField.SetIsTranslated(true); tlField.Save(trx); //} } } /////Translate Message sql.Clear(); sql.Append("SELECT * FROM I_TLMessage_trl WHERE IsContinueTranslation='Y' AND I_TLLanguage_ID=" + tlLanguageID); ds = DB.ExecuteDataset(sql.ToString()); if (ds != null) { X_I_TLMessage_Trl tlMsg = null; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tlMsg = new X_I_TLMessage_Trl(GetCtx(), ds.Tables[0].Rows[i], null); param = new System.Data.SqlClient.SqlParameter[2]; param[0] = new System.Data.SqlClient.SqlParameter("@Msg", tlMsg.GetMsgText()); if (string.IsNullOrEmpty(tlMsg.GetMsgTip())) { param[1] = new System.Data.SqlClient.SqlParameter("@MsgTip", DBNull.Value); } else { param[1] = new System.Data.SqlClient.SqlParameter("@MsgTip", tlMsg.GetMsgTip()); } sql.Clear(); sql.Append(@"Update AD_Message_TRL SET MsgText=@Msg, IsTranslated='Y', MsgTip=@MsgTip WHERE AD_Message_ID=" + tlMsg.GetAD_Message_ID() + " AND AD_LANGUAGE='" + lang + "'"); if (DB.ExecuteQuery(sql.ToString(), param, trx) == -1) { res.Append(tlMsg.GetAD_Message_ID() + " MessageNotTranslated."); break; } tlMsg.SetIsTranslated(true); tlMsg.Save(trx); //} } } ///Translate WIndow sql.Clear(); sql.Append("SELECT * FROM I_TLWindow_trl WHERE IsContinueTranslation='Y' AND I_TLLanguage_ID=" + tlLanguageID); ds = DB.ExecuteDataset(sql.ToString()); if (ds != null) { X_I_TLWindow_Trl tlWin = null; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tlWin = new X_I_TLWindow_Trl(GetCtx(), ds.Tables[0].Rows[i], null); param = new System.Data.SqlClient.SqlParameter[3]; param[0] = new System.Data.SqlClient.SqlParameter("@cname", tlWin.GetName()); desc = tlWin.GetDescription(); if (string.IsNullOrEmpty(desc)) { param[1] = new System.Data.SqlClient.SqlParameter("@description", DBNull.Value); } else { param[1] = new System.Data.SqlClient.SqlParameter("@description", desc); } help = tlWin.GetHelp(); if (string.IsNullOrEmpty(help)) { param[2] = new System.Data.SqlClient.SqlParameter("@help", DBNull.Value); } else { param[2] = new System.Data.SqlClient.SqlParameter("@help", help); } sql.Clear(); sql.Append(@"Update AD_Window_TRL SET Name=@cname, IsTranslated='Y', Description=@description, Help=@help WHERE AD_Window_ID=" + tlWin.GetAD_Window_ID() + " AND AD_LANGUAGE='" + lang + "'"); if (DB.ExecuteQuery(sql.ToString(), param, trx) == -1) { res.Append(tlWin.GetAD_Window_ID() + " WindowNotTranslated."); break; } tlWin.SetIsTranslated(true); tlWin.Save(trx); //} } } ///Translate tab sql.Clear(); sql.Append("SELECT * FROM I_TLtab_trl WHERE IsContinueTranslation='Y' AND I_TLLanguage_ID=" + tlLanguageID); ds = DB.ExecuteDataset(sql.ToString()); if (ds != null) { X_I_TLTab_Trl tlTab = null; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tlTab = new X_I_TLTab_Trl(GetCtx(), ds.Tables[0].Rows[i], null); param = new System.Data.SqlClient.SqlParameter[4]; param[0] = new System.Data.SqlClient.SqlParameter("@cname", tlTab.GetName()); desc = tlTab.GetDescription(); if (string.IsNullOrEmpty(desc)) { param[1] = new System.Data.SqlClient.SqlParameter("@description", DBNull.Value); } else { param[1] = new System.Data.SqlClient.SqlParameter("@description", desc); } help = tlTab.GetHelp(); if (string.IsNullOrEmpty(help)) { param[2] = new System.Data.SqlClient.SqlParameter("@help", DBNull.Value); } else { param[2] = new System.Data.SqlClient.SqlParameter("@help", help); } if (string.IsNullOrEmpty(tlTab.GetCommitWarning())) { param[3] = new System.Data.SqlClient.SqlParameter("@cm", DBNull.Value); } else { param[3] = new System.Data.SqlClient.SqlParameter("@cm", tlTab.GetCommitWarning()); } sql.Clear(); sql.Append(@"Update AD_Tab_TRL SET Name=@cname, IsTranslated='Y', Description=@description, Help=@help, CommitWarning=@cm WHERE AD_Tab_ID=" + tlTab.GetAD_Tab_ID() + " AND AD_LANGUAGE='" + lang + "'"); if (DB.ExecuteQuery(sql.ToString(), param, trx) == -1) { res.Append(tlTab.GetAD_Tab_ID() + " TabNotTranslated."); break; } tlTab.SetIsTranslated(true); tlTab.Save(trx); //} } } ///Translate FieldGroup sql.Clear(); sql.Append("SELECT * FROM I_TLFieldGroup_trl WHERE IsContinueTranslation='Y' AND I_TLLanguage_ID=" + tlLanguageID); ds = DB.ExecuteDataset(sql.ToString()); if (ds != null) { X_I_TLFieldGroup_Trl tlfg = null; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tlfg = new X_I_TLFieldGroup_Trl(GetCtx(), ds.Tables[0].Rows[i], null); param = new System.Data.SqlClient.SqlParameter[1]; param[0] = new System.Data.SqlClient.SqlParameter("@cname", tlfg.GetName()); sql.Clear(); sql.Append(@"Update AD_FieldGroup_TRL SET Name=@cname, IsTranslated='Y' WHERE AD_FieldGroup_ID=" + tlfg.GetAD_FieldGroup_ID() + " AND AD_LANGUAGE='" + lang + "'"); if (DB.ExecuteQuery(sql.ToString(), param, trx) == -1) { res.Append(tlfg.GetAD_FieldGroup_ID() + " FieldGroupNotTranslated."); break; } tlfg.SetIsTranslated(true); tlfg.Save(trx); //} } } ///Translate process sql.Clear(); sql.Append("SELECT * FROM I_TLProcess_trl WHERE IsContinueTranslation='Y' AND I_TLLanguage_ID=" + tlLanguageID); ds = DB.ExecuteDataset(sql.ToString()); if (ds != null) { X_I_TLProcess_Trl tlps = null; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tlps = new X_I_TLProcess_Trl(GetCtx(), ds.Tables[0].Rows[i], null); param = new System.Data.SqlClient.SqlParameter[3]; param[0] = new System.Data.SqlClient.SqlParameter("@cname", tlps.GetName()); desc = tlps.GetDescription(); if (string.IsNullOrEmpty(desc)) { param[1] = new System.Data.SqlClient.SqlParameter("@description", DBNull.Value); } else { param[1] = new System.Data.SqlClient.SqlParameter("@description", desc); } help = tlps.GetHelp(); if (string.IsNullOrEmpty(help)) { param[2] = new System.Data.SqlClient.SqlParameter("@help", DBNull.Value); } else { param[2] = new System.Data.SqlClient.SqlParameter("@help", help); } sql.Clear(); sql.Append(@"Update AD_process_TRL SET Name=@cname, IsTranslated='Y', Description=@description, Help=@help WHERE AD_process_ID=" + tlps.GetAD_Process_ID() + " AND AD_LANGUAGE='" + lang + "'"); if (DB.ExecuteQuery(sql.ToString(), param, trx) == -1) { res.Append(tlps.GetAD_Process_ID() + " ProcessNotTranslated."); break; } tlps.SetIsTranslated(true); tlps.Save(trx); //} } } ///Translate Form sql.Clear(); sql.Append("SELECT * FROM I_TLForm_trl WHERE IsContinueTranslation='Y' AND I_TLLanguage_ID=" + tlLanguageID); ds = DB.ExecuteDataset(sql.ToString()); if (ds != null) { X_I_TLForm_Trl tlps = null; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tlps = new X_I_TLForm_Trl(GetCtx(), ds.Tables[0].Rows[i], null); param = new System.Data.SqlClient.SqlParameter[3]; param[0] = new System.Data.SqlClient.SqlParameter("@cname", tlps.GetName()); desc = tlps.GetDescription(); if (string.IsNullOrEmpty(desc)) { param[1] = new System.Data.SqlClient.SqlParameter("@description", DBNull.Value); } else { param[1] = new System.Data.SqlClient.SqlParameter("@description", desc); } help = tlps.GetHelp(); if (string.IsNullOrEmpty(help)) { param[2] = new System.Data.SqlClient.SqlParameter("@help", DBNull.Value); } else { param[2] = new System.Data.SqlClient.SqlParameter("@help", help); } sql.Clear(); sql.Append(@"Update AD_Form_TRL SET Name=@cname, IsTranslated='Y', Description=@description, Help=@help WHERE AD_Form_ID=" + tlps.GetAD_Form_ID() + " AND AD_LANGUAGE='" + lang + "'"); if (DB.ExecuteQuery(sql.ToString(), param, trx) == -1) { res.Append(tlps.GetAD_Form_ID() + " FormNotTranslated."); break; } tlps.SetIsTranslated(true); tlps.Save(trx); //} } } ///Translate task sql.Clear(); sql.Append("SELECT * FROM I_TLTask_trl WHERE IsContinueTranslation='Y' AND I_TLLanguage_ID=" + tlLanguageID); ds = DB.ExecuteDataset(sql.ToString()); if (ds != null) { X_I_TLTask_Trl tlps = null; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tlps = new X_I_TLTask_Trl(GetCtx(), ds.Tables[0].Rows[i], null); param = new System.Data.SqlClient.SqlParameter[3]; param[0] = new System.Data.SqlClient.SqlParameter("@cname", tlps.GetName()); desc = tlps.GetDescription(); if (string.IsNullOrEmpty(desc)) { param[1] = new System.Data.SqlClient.SqlParameter("@description", DBNull.Value); } else { param[1] = new System.Data.SqlClient.SqlParameter("@description", desc); } help = tlps.GetHelp(); if (string.IsNullOrEmpty(help)) { param[2] = new System.Data.SqlClient.SqlParameter("@help", DBNull.Value); } else { param[2] = new System.Data.SqlClient.SqlParameter("@help", help); } sql.Clear(); sql.Append(@"Update AD_Task_TRL SET Name=@cname, IsTranslated='Y', Description=@description, Help=@help WHERE AD_Task_ID=" + tlps.GetAD_Task_ID() + " AND AD_LANGUAGE='" + lang + "'"); if (DB.ExecuteQuery(sql.ToString(), param, trx) == -1) { res.Append(tlps.GetAD_Task_ID() + " ProcessNotTranslated."); break; } tlps.SetIsTranslated(true); tlps.Save(trx); //} } } ///Translate Workflow sql.Clear(); sql.Append("SELECT * FROM I_TLWorkflow_trl WHERE IsContinueTranslation='Y' AND I_TLLanguage_ID=" + tlLanguageID); ds = DB.ExecuteDataset(sql.ToString()); if (ds != null) { X_I_TLWorkflow_Trl tlps = null; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tlps = new X_I_TLWorkflow_Trl(GetCtx(), ds.Tables[0].Rows[i], null); param = new System.Data.SqlClient.SqlParameter[3]; param[0] = new System.Data.SqlClient.SqlParameter("@cname", tlps.GetName()); desc = tlps.GetDescription(); if (string.IsNullOrEmpty(desc)) { param[1] = new System.Data.SqlClient.SqlParameter("@description", DBNull.Value); } else { param[1] = new System.Data.SqlClient.SqlParameter("@description", desc); } help = tlps.GetHelp(); if (string.IsNullOrEmpty(help)) { param[2] = new System.Data.SqlClient.SqlParameter("@help", DBNull.Value); } else { param[2] = new System.Data.SqlClient.SqlParameter("@help", help); } sql.Clear(); sql.Append(@"Update AD_Workflow_TRL SET Name=@cname, IsTranslated='Y', Description=@description, Help=@help WHERE AD_Workflow_ID=" + tlps.GetAD_Workflow_ID() + " AND AD_LANGUAGE='" + lang + "'"); if (DB.ExecuteQuery(sql.ToString(), param, trx) == -1) { res.Append(tlps.GetAD_Workflow_ID() + " WorkflowNotTranslated."); break; } tlps.SetIsTranslated(true); tlps.Save(trx); //} } } ///Translate WF_Node sql.Clear(); sql.Append("SELECT * FROM I_TLWF_Node_trl WHERE IsContinueTranslation='Y' AND I_TLLanguage_ID=" + tlLanguageID); ds = DB.ExecuteDataset(sql.ToString()); if (ds != null) { X_I_TLWF_Node_Trl tlps = null; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tlps = new X_I_TLWF_Node_Trl(GetCtx(), ds.Tables[0].Rows[i], null); param = new System.Data.SqlClient.SqlParameter[3]; param[0] = new System.Data.SqlClient.SqlParameter("@cname", tlps.GetName()); desc = tlps.GetDescription(); if (string.IsNullOrEmpty(desc)) { param[1] = new System.Data.SqlClient.SqlParameter("@description", DBNull.Value); } else { param[1] = new System.Data.SqlClient.SqlParameter("@description", desc); } help = tlps.GetHelp(); if (string.IsNullOrEmpty(help)) { param[2] = new System.Data.SqlClient.SqlParameter("@help", DBNull.Value); } else { param[2] = new System.Data.SqlClient.SqlParameter("@help", help); } sql.Clear(); sql.Append(@"Update AD_WF_Node_TRL SET Name=@cname, IsTranslated='Y', Description=@description, Help=@help WHERE AD_WF_Node_ID=" + tlps.GetAD_WF_Node_ID() + " AND AD_LANGUAGE='" + lang + "'"); if (DB.ExecuteQuery(sql.ToString(), param, trx) == -1) { res.Append(tlps.GetAD_WF_Node_ID() + " WF_NodeflowNotTranslated."); break; } tlps.SetIsTranslated(true); tlps.Save(trx); //} } } ///Translate Menu sql.Clear(); sql.Append("SELECT * FROM I_TLMenu_trl WHERE IsContinueTranslation='Y' AND I_TLLanguage_ID=" + tlLanguageID); ds = DB.ExecuteDataset(sql.ToString()); if (ds != null) { X_I_TLMenu_Trl tlps = null; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tlps = new X_I_TLMenu_Trl(GetCtx(), ds.Tables[0].Rows[i], null); param = new System.Data.SqlClient.SqlParameter[2]; param[0] = new System.Data.SqlClient.SqlParameter("@cname", tlps.GetName()); desc = tlps.GetDescription(); if (string.IsNullOrEmpty(desc)) { param[1] = new System.Data.SqlClient.SqlParameter("@description", DBNull.Value); } else { param[1] = new System.Data.SqlClient.SqlParameter("@description", desc); } sql.Clear(); sql.Append(@"Update AD_Menu_TRL SET Name=@cname, IsTranslated='Y', Description=@description WHERE AD_Menu_ID=" + tlps.GetAD_Menu_ID() + " AND AD_LANGUAGE='" + lang + "'"); if (DB.ExecuteQuery(sql.ToString(), param, trx) == -1) { res.Append(tlps.GetAD_Menu_ID() + " MenuNotTranslated."); break; } tlps.SetIsTranslated(true); tlps.Save(trx); //} } } ///Translate Ref_List sql.Clear(); sql.Append("SELECT * FROM I_TLRef_List_trl WHERE IsContinueTranslation='Y' AND I_TLLanguage_ID=" + tlLanguageID); ds = DB.ExecuteDataset(sql.ToString()); if (ds != null) { X_I_TLRef_List_Trl tlps = null; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tlps = new X_I_TLRef_List_Trl(GetCtx(), ds.Tables[0].Rows[i], null); param = new System.Data.SqlClient.SqlParameter[2]; param[0] = new System.Data.SqlClient.SqlParameter("@cname", tlps.GetName()); desc = tlps.GetDescription(); if (string.IsNullOrEmpty(desc)) { param[1] = new System.Data.SqlClient.SqlParameter("@description", DBNull.Value); } else { param[1] = new System.Data.SqlClient.SqlParameter("@description", desc); } sql.Clear(); sql.Append(@"Update AD_Ref_List_TRL SET Name=@cname, IsTranslated='Y', Description=@description WHERE AD_Ref_List_ID=" + tlps.GetAD_Ref_List_ID() + " AND AD_LANGUAGE='" + lang + "'"); if (DB.ExecuteQuery(sql.ToString(), param, trx) == -1) { res.Append(tlps.GetAD_Ref_List_ID() + " Ref_ListNotTranslated."); break; } tlps.SetIsTranslated(true); tlps.Save(trx); //} } } if (res.Length == 0) { res.Append("DONE"); trx.Commit(); } else { trx.Rollback(); } trx.Close(); return(res.ToString()); //throw new NotImplementedException(); }
/** * Update / Create Balances. * Called from FinReport, FactAcctReset (indirect) * @param AD_Client_ID client * @param C_AcctSchema_ID accounting schema 0 for all * @param deleteFirst delete balances first * @param dateFrom null for all or first date to delete/calculate * @param trx transaction * @param svrPrc optional server process * @return Message to be translated */ public static String UpdateBalance(Ctx ctx, int C_AcctSchema_ID, DateTime?dateFrom, Trx trxp, int Fact_Accumulation_ID, SvrProcess svrPrc) { Trx trx = trxp; _log.Info("C_AcctSchema_ID=" + C_AcctSchema_ID + "DateFrom=" + dateFrom); long start = CommonFunctions.CurrentTimeMillis(); //List<Object> param = new List<Object>(); List <MFactAccumulation> accums = null; int no = 0; if (Fact_Accumulation_ID == 0) { accums = MFactAccumulation.GetAll(ctx, C_AcctSchema_ID); if (accums.Count == 0) { // Create a Balance aggregation of type Daily. MFactAccumulation defaultAccum = new MFactAccumulation(ctx, 0, trx); defaultAccum.SetAD_Client_ID(ctx.GetAD_Client_ID()); defaultAccum.SetAD_Org_ID(ctx.GetAD_Org_ID()); defaultAccum.SetC_AcctSchema_ID(C_AcctSchema_ID); defaultAccum.SetBALANCEACCUMULATION(X_Fact_Accumulation.BALANCEACCUMULATION_Daily); defaultAccum.SetIsActive(true); defaultAccum.SetIsDefault(true); defaultAccum.SetISACTIVITY(true); defaultAccum.SetISBUDGET(true); defaultAccum.SetISBUSINESSPARTNER(true); defaultAccum.SetISCAMPAIGN(true); defaultAccum.SetISLOCATIONFROM(true); defaultAccum.SetISLOCATIONTO(true); defaultAccum.SetISPRODUCT(true); defaultAccum.SetISPROJECT(true); defaultAccum.SetISSALESREGION(true); defaultAccum.SetISUSERLIST1(true); defaultAccum.SetISUSERLIST2(true); defaultAccum.SetISUSERELEMENT1(true); defaultAccum.SetISUSERELEMENT2(true); if (!defaultAccum.Save(trx)) { _log.Log(Level.SEVERE, "Unable to create Default Balance Aggregation"); return("Unable to create Default Balance Aggregation"); } else { accums.Add(defaultAccum); } } } else { MFactAccumulation selectAccum = new MFactAccumulation(ctx, Fact_Accumulation_ID, trx); accums = new List <MFactAccumulation>(); accums.Add(selectAccum); } foreach (MFactAccumulation accum in accums) { // dateFrom = MFactAccumulation.GetDateFrom(accum, dateFrom); dateFrom = accum.GetDateFrom(); String type = accum.GetBALANCEACCUMULATION(); String trunc = null; if (X_Fact_Accumulation.BALANCEACCUMULATION_Daily.Equals(type)) { trunc = TimeUtil.TRUNC_DAY; } else if (X_Fact_Accumulation.BALANCEACCUMULATION_CalendarWeek.Equals(type)) { trunc = TimeUtil.TRUNC_WEEK; } else if (X_Fact_Accumulation.BALANCEACCUMULATION_CalendarMonth.Equals(type)) { trunc = TimeUtil.TRUNC_MONTH; } if (X_Fact_Accumulation.BALANCEACCUMULATION_PeriodOfAViennaCalendar.Equals(type) && !CheckPeriod(accum, dateFrom)) { _log.Log(Level.SEVERE, "Necessary Period doesn't exist for the calendar"); return("Necessary Period doesn't exist for the calendar"); } String dateClause = null; if (X_Fact_Accumulation.BALANCEACCUMULATION_PeriodOfAViennaCalendar.Equals(type)) { dateClause = " Period.StartDate "; } else { dateClause = " a.DateAcct "; _log.Fine(trunc); //dateClause = " TRUNC(a.DateAcct, '" + trunc + "' ) "; } // Delete the balances DeleteBalance(ctx.GetAD_Client_ID(), C_AcctSchema_ID, dateFrom, trx, accum.GetFACT_ACCUMULATION_ID(), svrPrc); /** Insert **/ //param = new List<Object>(); String insert = "INSERT INTO Fact_Acct_Balance " + "(AD_Client_ID, AD_Org_ID, AD_OrgTrx_ID, C_AcctSchema_ID, DateAcct," + " Account_ID, PostingType, Fact_Accumulation_ID, M_Product_ID, C_BPartner_ID," + " C_Project_ID, C_SalesRegion_ID,C_Activity_ID," + " C_Campaign_ID, C_LocTo_ID, C_LocFrom_ID, User1_ID, User2_ID, GL_Budget_ID," + " UserElement1_ID, UserElement2_ID, " + " AmtAcctDr, AmtAcctCr, Qty) "; String select = " SELECT AD_Client_ID, AD_Org_ID, AD_OrgTrx_ID, C_AcctSchema_ID, "; select = select + dateClause; select = select + " ,Account_ID, PostingType, " + accum.GetFACT_ACCUMULATION_ID(); if (accum.IsPRODUCT()) { select = select + " ,M_Product_ID "; } else { select = select + " , NULL "; } if (accum.IsBUSINESSPARTNER()) { select = select + " , C_BPartner_ID "; } else { select = select + " ,NULL "; } if (accum.IsPROJECT()) { select = select + " ,C_Project_ID "; } else { select = select + " , NULL "; } if (accum.IsSALESREGION()) { select = select + ", C_SalesRegion_ID "; } else { select = select + " ,NULL "; } if (accum.IsACTIVITY()) { select = select + " ,C_Activity_ID "; } else { select = select + " ,NULL "; } if (accum.IsCAMPAIGN()) { select = select + " ,C_Campaign_ID "; } else { select = select + " ,NULL "; } if (accum.IsLOCATIONTO()) { select = select + " ,C_LocTo_ID "; } else { select = select + " ,NULL "; } if (accum.IsLOCATIONFROM()) { select = select + " ,C_LocFrom_ID "; } else { select = select + " ,NULL "; } if (accum.IsUSERLIST1()) { select = select + " ,User1_ID "; } else { select = select + " ,NULL "; } if (accum.IsUSERLIST2()) { select = select + " ,User2_ID "; } else { select = select + " ,NULL "; } if (accum.IsBUDGET()) { select = select + " ,GL_Budget_ID "; } else { select = select + " ,NULL "; } if (accum.IsUSERELEMENT1()) { select = select + " ,UserElement1_ID "; } else { select = select + " ,NULL "; } if (accum.IsUSERELEMENT2()) { select = select + " , UserElement2_ID "; } else { select = select + " ,NULL "; } select = select + " ,COALESCE(SUM(AmtAcctDr),0), COALESCE(SUM(AmtAcctCr),0), COALESCE(SUM(Qty),0) "; String from = " FROM Fact_Acct a "; if (X_Fact_Accumulation.BALANCEACCUMULATION_PeriodOfAViennaCalendar.Equals(type)) { from += " ,(SELECT StartDate,EndDate FROM C_Period " + " WHERE C_Year_ID IN (SELECT C_Year_ID " + " FROM C_Year WHERE C_Calendar_ID= " + accum.GetC_Calendar_ID() + " ) " + " AND IsActive='Y' AND PeriodType='S') Period"; //param.add(new Integer(accum.GetC_Calendar_ID())); } String where = " WHERE C_AcctSchema_ID= " + C_AcctSchema_ID; if (X_Fact_Accumulation.BALANCEACCUMULATION_PeriodOfAViennaCalendar.Equals(type)) { where += " AND a.DateAcct BETWEEN TRUNC(Period.StartDate,'DD') AND TRUNC(Period.EndDate,'DD') "; } //param.add(new Integer(C_AcctSchema_ID)); if (dateFrom != null) { //SimpleDateFormat df = new SimpleDateFormat();//"dd-MM-yyyy" //String finalDate = df.Format(dateFrom); //where += " AND DateAcct>= TO_DATE('" + finalDate + "','DD-MM-YYYY') "; where += " AND DateAcct >= " + DB.TO_DATE(dateFrom); } String groupBy = " GROUP BY AD_Client_ID,C_AcctSchema_ID, AD_Org_ID, " + " AD_OrgTrx_ID,Account_ID, PostingType," + dateClause; if (accum.IsPRODUCT()) { groupBy = groupBy + " ,M_Product_ID "; } if (accum.IsBUSINESSPARTNER()) { groupBy = groupBy + " ,C_BPartner_ID "; } if (accum.IsPROJECT()) { groupBy = groupBy + " ,C_Project_ID "; } if (accum.IsSALESREGION()) { groupBy = groupBy + " ,C_SalesRegion_ID "; } if (accum.IsACTIVITY()) { groupBy = groupBy + ", C_Activity_ID "; } if (accum.IsCAMPAIGN()) { groupBy = groupBy + " ,C_Campaign_ID "; } if (accum.IsLOCATIONTO()) { groupBy = groupBy + ", C_LocTo_ID "; } if (accum.IsLOCATIONFROM()) { groupBy = groupBy + ", C_LocFrom_ID "; } if (accum.IsUSERLIST1()) { groupBy = groupBy + ", User1_ID"; } if (accum.IsUSERLIST2()) { groupBy = groupBy + ", User2_ID "; } if (accum.IsBUDGET()) { groupBy = groupBy + ", GL_Budget_ID "; } if (accum.IsUSERELEMENT1()) { groupBy = groupBy + ", UserElement1_ID "; } if (accum.IsUSERELEMENT2()) { groupBy = groupBy + ", UserElement2_ID "; } String sql = insert + select + from + where + groupBy; no = DB.ExecuteQuery(sql, null, trx); _log.Config("Inserts=" + no); if (svrPrc != null) { svrPrc.AddLog(0, dateFrom, new Decimal(no), "Inserts in " + accum.ToString()); } trx.Commit(); } start = CommonFunctions.CurrentTimeMillis() - start; _log.Info((start / 1000) + " sec"); return("#" + no); }
/// <summary> /// Starts the process /// </summary> /// <param name="ctx">context</param> /// <param name="pi">ProcessInfo object</param> /// <returns></returns> public bool StartProcess(Ctx ctx, ProcessInfo pi, Trx trx) { // Preparation _pi = pi; PrepareCtx(ctx); //ctxContext = ctx == null ? Utility.Env.GetCtx() : ctx; _trx = trx; bool localTrx = _trx == null; if (localTrx) { _trx = Trx.GetTrx("SvrProcess"); } //trx = SqlExec.ExecuteQuery.GerServerTransaction(); String msg = null; bool success = true; try { Lock(); Prepare(); msg = DoIt(); } catch (Exception e) { msg = e.Message; if (msg == null) { msg = e.ToString(); } if (e.Message != null) { log.Log(Level.SEVERE, msg); } else if (VLogMgt.IsLevelFiner()) { log.Log(Level.WARNING, msg); } else { log.Warning(msg); } success = false; } if (localTrx && _trx != null) { if (success) { _trx.Commit(); } else { _trx.Rollback(); } _trx.Close(); _trx = null; } // Parse Variables msg = Utility.Msg.ParseTranslation(ctx, msg); _pi.SetSummary(msg, !success); ProcessInfoUtil.SaveLogToDB(_pi); Unlock(); return(success); }
/// <summary> /// is used to save data in case of Full move container / full qty move /// </summary> /// <param name="movementId">movement header refernce</param> /// <param name="fromLocatorId">From Locator - from where we have to move product</param> /// <param name="fromContainerId">From Container - from which container, we have to move product</param> /// <param name="toLocatorId">To Locator - where we are moving product</param> /// <param name="toContainerId">To container - in which container we are moving product</param> /// <param name="lineNo"></param> /// <param name="isMoveFullContainerQty">Is Container also move with Product</param> /// <param name="trx">Self created Trx</param> /// <returns>Message : lines inserted or not</returns> public String SaveMoveLinewithFullContainer(int movementId, int fromLocatorId, int fromContainerId, int toLocatorId, int toContainerId, int lineNo, bool isMoveFullContainerQty, Trx trx) { MMovement movement = new MMovement(_ctx, movementId, trx); string childContainerId = null; StringBuilder error = new StringBuilder(); // Get Path upto selected container string sql = @"SELECT sys_connect_by_path(m_productcontainer_id,'->') tree FROM m_productcontainer WHERE m_productcontainer_id = " + fromContainerId + @" START WITH ref_m_container_id IS NULL CONNECT BY prior m_productcontainer_id = ref_m_container_id ORDER BY tree "; string pathContainer = Util.GetValueOfString(DB.ExecuteScalar(sql, null, trx)); // child records with Parent Id if (!isMoveFullContainerQty) { sql = @"SELECT tree, m_productcontainer_id FROM (SELECT sys_connect_by_path(m_productcontainer_id,'->') tree , m_productcontainer_id FROM m_productcontainer START WITH ref_m_container_id IS NULL CONNECT BY prior m_productcontainer_id = ref_m_container_id ORDER BY tree ) WHERE tree LIKE ('" + pathContainer + "%') "; DataSet ds = DB.ExecuteDataset(sql, null, trx); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (String.IsNullOrEmpty(childContainerId)) { childContainerId = Util.GetValueOfString(ds.Tables[0].Rows[i]["m_productcontainer_id"]); } else { childContainerId += "," + Util.GetValueOfString(ds.Tables[0].Rows[i]["m_productcontainer_id"]); } } } ds.Dispose(); } else { childContainerId = fromContainerId.ToString(); } // check is same container already moved to another container // Ex :: p1 -> c1 and p1 -> c2 // OR also check -- is any other container is moving into exist target container // Ex :: p1 -> c1 and p2 -> p1 if (!isMoveFullContainerQty) { if (!IsContainerMoved(movementId, pathContainer, childContainerId, toContainerId, trx)) { return(Msg.GetMsg(_ctx, "VIS_AlreadyMoved")); } } // not to move Parent container to its child container if (toContainerId > 0 && childContainerId.Contains(toContainerId.ToString())) { //Parent cant be Move to its own child return(Msg.GetMsg(_ctx, "VIS_cantMoveParentTochild")); } // Get All records of Parent Container and child container sql = @"SELECT * FROM ( SELECT p.M_PRODUCT_ID, p.NAME, p.C_UOM_ID, u.Name AS UomName, t.M_ATTRIBUTESETINSTANCE_ID, t.M_ProductContainer_ID, SUM(t.ContainerCurrentQty) keep (dense_rank last ORDER BY t.MovementDate, t.M_Transaction_ID) AS ContainerCurrentQty FROM M_Transaction t INNER JOIN M_Product p ON p.M_Product_ID = t.M_Product_ID INNER JOIN C_UOM u ON u.C_UOM_ID = p.C_UOM_ID WHERE t.IsActive = 'Y' AND NVL(t.M_ProductContainer_ID, 0) IN ( " + childContainerId + @" ) AND t.MovementDate <=" + GlobalVariable.TO_DATE(movement.GetMovementDate(), true) + @" AND t.M_Locator_ID = " + fromLocatorId + @" AND t.AD_Client_ID = " + movement.GetAD_Client_ID() + @" GROUP BY p.M_PRODUCT_ID, p.NAME, p.C_UOM_ID, u.Name, t.M_ATTRIBUTESETINSTANCE_ID, t.M_ProductContainer_ID ) t WHERE ContainerCurrentQty <> 0 "; DataSet dsRecords = DB.ExecuteDataset(sql, null, trx); if (dsRecords != null && dsRecords.Tables.Count > 0 && dsRecords.Tables[0].Rows.Count > 0) { int movementlineId = 0; MMovementLine moveline = null; MProduct product = null; for (int i = 0; i < dsRecords.Tables[0].Rows.Count; i++) { movementlineId = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT NVL(M_MovementLine_ID, 0) AS M_Movement_ID FROM M_MovementLine WHERE M_Movement_ID = " + Util.GetValueOfInt(movementId) + @" AND M_Product_ID = " + Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_Product_ID"]) + @" AND NVL(M_AttributeSetInstance_ID, 0) = " + Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_AttributeSetInstance_ID"]) + @" AND M_Locator_ID = " + Util.GetValueOfInt(fromLocatorId) + @" AND NVL(M_ProductContainer_ID, 0) = " + Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_ProductContainer_ID"]) + @" AND M_LocatorTo_ID = " + Util.GetValueOfInt(toLocatorId) + @" AND NVL(Ref_M_ProductContainerTo_ID, 0) = " + toContainerId + @" AND AD_Org_ID = " + movement.GetAD_Org_ID())); if (movementlineId > 0) { moveline = new MMovementLine(_ctx, movementlineId, trx); } else { moveline = new MMovementLine(_ctx, 0, trx); } if (movementlineId == 0) { #region Create new record of movement line lineNo += 10; moveline.SetAD_Client_ID(movement.GetAD_Client_ID()); moveline.SetAD_Org_ID(movement.GetAD_Org_ID()); moveline.SetM_Movement_ID(movement.GetM_Movement_ID()); moveline.SetLine(lineNo); moveline.SetM_Product_ID(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_Product_ID"])); moveline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_AttributeSetInstance_ID"])); moveline.SetC_UOM_ID(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["C_UOM_ID"])); moveline.SetM_Locator_ID(fromLocatorId); moveline.SetM_LocatorTo_ID(toLocatorId); moveline.SetM_ProductContainer_ID(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_ProductContainer_ID"])); moveline.SetRef_M_ProductContainerTo_ID(toContainerId); moveline.SetQtyEntered(Util.GetValueOfDecimal(dsRecords.Tables[0].Rows[i]["ContainerCurrentQty"])); moveline.SetMovementQty(Util.GetValueOfDecimal(dsRecords.Tables[0].Rows[i]["ContainerCurrentQty"])); moveline.SetMoveFullContainer(isMoveFullContainerQty ? false : true); // when move full container, then only need to update IsParentMove and Target container (which represent - to which container we are moving) // and set true value on those line which container are moving, not on its child container if (!isMoveFullContainerQty) { moveline.SetIsParentMove(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_ProductContainer_ID"]) == fromContainerId ? true : false); moveline.SetTargetContainer_ID(fromContainerId); } #endregion } else { #region Update record of movement line moveline.SetQtyEntered(Decimal.Add(moveline.GetQtyEntered(), Util.GetValueOfDecimal(dsRecords.Tables[0].Rows[i]["ContainerCurrentQty"]))); moveline.SetMovementQty(Decimal.Add(moveline.GetMovementQty(), Util.GetValueOfDecimal(dsRecords.Tables[0].Rows[i]["ContainerCurrentQty"]))); moveline.SetMoveFullContainer(true); #endregion } if (!moveline.Save(trx)) { #region Save error catch and rollback product = MProduct.Get(_ctx, Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_Product_ID"])); ValueNamePair pp = VLogger.RetrieveError(); if (pp != null) { _log.SaveError("Movement line not inserted through Move Container Form : ", pp.GetName()); if (String.IsNullOrEmpty(error.ToString())) { error.Append(Msg.GetMsg(_ctx, "VIS_MoveLineNotSaveFor") + product.GetName() + Msg.GetMsg(_ctx, "VIS_DueTo") + pp.GetName()); } else { error.Append(" , " + Msg.GetMsg(_ctx, "VIS_MoveLineNotSaveFor") + product.GetName() + Msg.GetMsg(_ctx, "VIS_DueTo") + pp.GetName()); } } trx.Rollback(); #endregion } else { trx.Commit(); } } } else { return(Msg.GetMsg(_ctx, "VIS_ContainerhaveNoRecord")); } return(String.IsNullOrEmpty(error.ToString()) ? "VIS_SuccessFullyInserted" : error.ToString()); }
/// <summary> /// Is used to save data on movememt line /// </summary> /// <param name="mData"></param> /// <returns></returns> public String SaveMovementLine(List <Dictionary <string, string> > mData) { StringBuilder error = new StringBuilder(); bool isMoveFullContainer = false; bool isMoveFullContainerQty = false; Trx trx = Trx.GetTrx("Movement"); if (mData.Count > 0) { isMoveFullContainer = Util.GetValueOfBool(mData[0]["IsFullMoveContainer"]); //to delete all the movement lines where MoveFullContainer is False if (isMoveFullContainer) { DB.ExecuteQuery("DELETE FROM M_MovementLine WHERE M_Movement_ID = " + Util.GetValueOfInt(mData[0]["M_Movement_ID"]) + " AND MoveFullContainer= 'N' ", null, null); } // Lines not inserted, as movement line already has a full move container line. if (!isMoveFullContainer) { if (Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT COUNT(MoveFullContainer) FROM M_MovementLine WHERE MoveFullContainer= 'Y' AND M_Movement_ID = " + Util.GetValueOfInt(mData[0]["M_Movement_ID"]), null, trx)) > 0) { trx.Close(); return(Msg.GetMsg(_ctx, "VIS_LinehaveFullContainer")); } } // Get Line No int lineNo = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT NVL(MAX(Line),0) AS DefaultValue FROM M_MovementLine WHERE M_Movement_ID=" + Util.GetValueOfInt(mData[0]["M_Movement_ID"]), null, trx)); isMoveFullContainerQty = Util.GetValueOfBool(mData[0]["IsfullContainerQtyWise"]); if (!isMoveFullContainer && !isMoveFullContainerQty) { goto moveFullContainer; } else if (isMoveFullContainer || isMoveFullContainerQty) { error.Clear(); error.Append(SaveMoveLinewithFullContainer(Util.GetValueOfInt(mData[0]["M_Movement_ID"]), Util.GetValueOfInt(mData[0]["FromLocator"]), Util.GetValueOfInt(mData[0]["FromContainer"]), Util.GetValueOfInt(mData[0]["ToLocator"]), Util.GetValueOfInt(mData[0]["ToContainer"]), lineNo, isMoveFullContainerQty, trx)); trx.Close(); return(error.ToString()); } moveFullContainer: MMovementLine moveline = null; MProduct product = null; int moveId = 0; for (int i = 0; i < mData.Count; i++) { #region Quantity Only MMovement move = new MMovement(_ctx, Util.GetValueOfInt(mData[i]["M_Movement_ID"]), null); moveId = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT NVL(M_MovementLine_ID, 0) AS M_Movement_ID FROM M_MovementLine WHERE M_Movement_ID = " + Util.GetValueOfInt(mData[i]["M_Movement_ID"]) + @" AND M_Product_ID = " + Util.GetValueOfInt(mData[i]["M_Product_ID"]) + @" AND NVL(M_AttributeSetInstance_ID, 0) = " + Util.GetValueOfInt(mData[i]["M_AttributeSetInstance_ID"]) + @" AND M_Locator_ID = " + Util.GetValueOfInt(mData[i]["FromLocator"]) + @" AND NVL(M_ProductContainer_ID, 0) = " + Util.GetValueOfInt(mData[i]["FromContainer"]) + @" AND M_LocatorTo_ID = " + Util.GetValueOfInt(mData[i]["ToLocator"]) + @" AND NVL(Ref_M_ProductContainerTo_ID, 0) = " + Util.GetValueOfInt(mData[i]["ToContainer"]) + @" AND AD_Org_ID = " + move.GetAD_Org_ID())); if (moveId > 0) { moveline = new MMovementLine(_ctx, moveId, trx); } else { moveline = new MMovementLine(_ctx, 0, trx); } if (moveId == 0) { #region Create new record of movement line lineNo += 10; moveline.SetAD_Client_ID(move.GetAD_Client_ID()); moveline.SetAD_Org_ID(move.GetAD_Org_ID()); moveline.SetM_Movement_ID(move.GetM_Movement_ID()); moveline.SetLine(lineNo); moveline.SetM_Product_ID(Util.GetValueOfInt(mData[i]["M_Product_ID"])); moveline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(mData[i]["M_AttributeSetInstance_ID"])); moveline.SetC_UOM_ID(Util.GetValueOfInt(mData[i]["C_UOM_ID"])); moveline.SetM_Locator_ID(Util.GetValueOfInt(mData[i]["FromLocator"])); moveline.SetM_LocatorTo_ID(Util.GetValueOfInt(mData[i]["ToLocator"])); moveline.SetM_ProductContainer_ID(Util.GetValueOfInt(mData[i]["FromContainer"])); moveline.SetRef_M_ProductContainerTo_ID(Util.GetValueOfInt(mData[i]["ToContainer"])); moveline.SetQtyEntered(Util.GetValueOfDecimal(mData[i]["MoveQty"])); moveline.SetMovementQty(Util.GetValueOfDecimal(mData[i]["MoveQty"])); moveline.SetMoveFullContainer(Util.GetValueOfBool(mData[i]["IsFullMoveContainer"])); #endregion } else { #region Update record of movement line moveline.SetQtyEntered(Decimal.Add(moveline.GetQtyEntered(), Util.GetValueOfDecimal(mData[i]["MoveQty"]))); moveline.SetMovementQty(Decimal.Add(moveline.GetMovementQty(), Util.GetValueOfDecimal(mData[i]["MoveQty"]))); moveline.SetMoveFullContainer(Util.GetValueOfBool(mData[i]["IsFullMoveContainer"])); #endregion } if (!moveline.Save(trx)) { #region Save error catch and rollback product = MProduct.Get(_ctx, Util.GetValueOfInt(mData[i]["M_Product_ID"])); ValueNamePair pp = VLogger.RetrieveError(); if (pp != null) { _log.SaveError("Movement line not inserted through Move Container Form : ", pp.GetName()); if (String.IsNullOrEmpty(error.ToString())) { error.Append(Msg.GetMsg(_ctx, "VIS_MoveLineNotSaveFor") + product.GetName() + Msg.GetMsg(_ctx, "VIS_DueTo") + pp.GetName()); } else { error.Append(" , " + Msg.GetMsg(_ctx, "VIS_MoveLineNotSaveFor") + product.GetName() + Msg.GetMsg(_ctx, "VIS_DueTo") + pp.GetName()); } } trx.Rollback(); #endregion } else { trx.Commit(); } #endregion } } trx.Close(); return(String.IsNullOrEmpty(error.ToString()) ? "VIS_SuccessFullyInserted" : error.ToString()); }