//Added by Arpit on 15th Dec,2016 public static MJournal CopyFrom(Ctx ctx, int GL_Journal_ID, DateTime?dateDoc, Trx trxName) { MJournal from = new MJournal(ctx, GL_Journal_ID, trxName); if (from.GetGL_Journal_ID() == 0) { throw new ArgumentException("From Journal Batch not found GL_JournalBatch_ID=" + GL_Journal_ID); } // MJournal to = new MJournal(ctx, 0, trxName); PO.CopyValues(from, to, from.GetAD_Client_ID(), from.GetAD_Org_ID()); to.Set_ValueNoCheck("DocumentNo", null); // to.Set_ValueNoCheck("C_Period_ID", null); to.SetDateAcct(dateDoc); to.SetDateDoc(dateDoc); to.SetDocStatus(DOCSTATUS_Drafted); to.SetDocAction(DOCACTION_Complete); to.SetIsApproved(false); to.SetProcessed(false); from.GetType(); // if (!to.Save()) { throw new Exception("Could not create GL Journal "); } if (to.CopyJLines(from, dateDoc) == 0) { throw new Exception("Could not create GL Journal Details"); } return(to); } // copyFrom
} // MJournalLine /// <summary> /// Parent Constructor /// </summary> /// <param name="parent">journal</param> public MJournalLine(MJournal parent) : this(parent.GetCtx(), 0, parent.Get_TrxName()) { //this (parent.getCtx(), 0, parent.get_TrxName()); SetClientOrg(parent); SetGL_Journal_ID(parent.GetGL_Journal_ID()); SetC_Currency_ID(parent.GetC_Currency_ID()); SetC_ConversionType_ID(parent.GetC_ConversionType_ID()); SetDateAcct(parent.GetDateAcct()); } // MJournalLine
} // toString /// <summary> /// Execute Run. /// </summary> /// <returns>clear text info</returns> public String ExecuteRun() { DateTime?dateDoc = GetDateNextRun(); if (!CalculateRuns()) { throw new Exception("No Runs Left"); } // log MRecurringRun run = new MRecurringRun(GetCtx(), this); String msg = "@Created@ "; //Checked if the Next Date Run is less then the date pressent Arpit on 15th Dec,2016 if (GetDateNextRun() == DateTime.Now.Date || GetDateNextRun() == null) { // Copy if (GetRecurringType().Equals(MRecurring.RECURRINGTYPE_Order)) { MOrder from = new MOrder(GetCtx(), GetC_Order_ID(), Get_TrxName()); MOrder order = MOrder.CopyFrom(from, dateDoc, from.GetC_DocType_ID(), false, false, Get_TrxName()); run.SetC_Order_ID(order.GetC_Order_ID()); msg += order.GetDocumentNo(); } else if (GetRecurringType().Equals(MRecurring.RECURRINGTYPE_Invoice)) { MInvoice from = new MInvoice(GetCtx(), GetC_Invoice_ID(), Get_TrxName()); MInvoice invoice = MInvoice.CopyFrom(from, dateDoc, from.GetC_DocType_ID(), false, Get_TrxName(), false); run.SetC_Invoice_ID(invoice.GetC_Invoice_ID()); //Set Invoice Refrence and Description from Orignal to Recurring invoice.Set_Value("InvoiceReference", from.GetDocumentNo() + "_" + (GetRunsMax() - GetRunsRemaining() + 1)); invoice.AddDescription(Msg.GetMsg(from.GetCtx(), "RecurringDocument") + from.GetDocumentNo()); if (!invoice.Save(Get_TrxName())) { ValueNamePair pp = VLogger.RetrieveError(); if (pp != null) { from.SetProcessMsg(Msg.GetMsg(from.GetCtx(), "CouldNotCreateInvoice") + pp.GetName()); } else { from.SetProcessMsg(Msg.GetMsg(from.GetCtx(), "CouldNotCreateInvoice")); } throw new Exception(Msg.GetMsg(from.GetCtx(), "CouldNotCreateInvoice") + (pp != null ? pp.GetName() : "")); } msg += invoice.GetDocumentNo(); } else if (GetRecurringType().Equals(MRecurring.RECURRINGTYPE_Project)) { MProject project = MProject.CopyFrom(GetCtx(), GetC_Project_ID(), dateDoc, Get_TrxName()); run.SetC_Project_ID(project.GetC_Project_ID()); msg += project.GetValue(); } else if (GetRecurringType().Equals(MRecurring.RECURRINGTYPE_GLJournalBatch)) //Changes to GL Journal Batch by Arpit { MJournalBatch journal = MJournalBatch.CopyFrom(GetCtx(), GetGL_JournalBatch_ID(), dateDoc, Get_TrxName()); run.SetGL_JournalBatch_ID(journal.GetGL_JournalBatch_ID()); msg += journal.GetDocumentNo(); } //Added by Arpit on 14th, Dec,2016 else if (GetRecurringType().Equals(MRecurring.RECURRINGTYPE_GLJournal)) { MJournal Journal = MJournal.CopyFrom(GetCtx(), GetGL_Journal_ID(), dateDoc, Get_TrxName()); run.SetGL_Journal_ID(Journal.GetGL_Journal_ID()); msg += Journal.GetDocumentNo(); } //End here else if (GetRecurringType().Equals(MRecurring.RECURRINGTYPE_Payment)) { MPayment from = new MPayment(GetCtx(), GetC_Payment_ID(), Get_TrxName()); MPayment payment = MPayment.CopyFrom(from, dateDoc, from.GetC_DocType_ID(), Get_TrxName()); run.SetC_Payment_ID(payment.GetC_Payment_ID()); msg += payment.GetDocumentNo(); } else { return("Invalid @RecurringType@ = " + GetRecurringType()); } run.Save(Get_TrxName()); // SetDateLastRun(run.GetUpdated()); SetRunsRemaining(GetRunsRemaining() - 1); SetDateNextRun(); Save(Get_TrxName()); return(msg); } else { return(Msg.GetMsg(GetCtx(), "RecurringNotCompleted") + String.Format("{0:dd/M/yyyy}", Convert.ToDateTime(GetDateNextRun()))); } } // execureRun