예제 #1
0
        }       //	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@ ";


            //	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());
                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_GLJournal))
            {
                MJournalBatch journal = MJournalBatch.CopyFrom(GetCtx(), GetGL_JournalBatch_ID(), dateDoc, Get_TrxName());
                run.SetGL_JournalBatch_ID(journal.GetGL_JournalBatch_ID());
                msg += journal.GetDocumentNo();
            }
            else
            {
                return("Invalid @RecurringType@ = " + GetRecurringType());
            }
            run.Save(Get_TrxName());

            //
            SetDateLastRun(run.GetUpdated());
            SetRunsRemaining(GetRunsRemaining() - 1);
            SetDateNextRun();
            Save(Get_TrxName());
            return(msg);
        }       //	execureRun
        protected override string DoIt()
        {
            ds = new DataSet();

            ds = DB.ExecuteDataset("SELECT C_Recurring_ID From C_Recurring Where IsActive='Y' AND AD_Client_ID=" + GetAD_Client_ID()
                                   + " AND TRUNC(DateNextRun)=" + GlobalVariable.TO_DATE(DateTime.Now, true));
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                for (Int32 i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    Recurring = new MRecurring(GetCtx(), Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_Recurring_ID"]), Get_Trx());
                    dateDoc   = Recurring.GetDateNextRun();
                    if (dateDoc != null && Recurring.CalculateRuns())
                    {
                        //  throw new Exception("No Runs Left");
                        MRecurringRun run = new MRecurringRun(GetCtx(), Recurring);
                        String        msg = "@Created@ ";
                        // if (Recurring.GetDateNextRun() == DateTime.Now.Date || Recurring.GetDateNextRun() == null)
                        //{
                        //	Copy
                        if (Recurring.GetRecurringType().Equals(MRecurring.RECURRINGTYPE_Order))
                        {
                            MOrder from  = new MOrder(GetCtx(), Recurring.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 (Recurring.GetRecurringType().Equals(MRecurring.RECURRINGTYPE_Invoice))
                        {
                            MInvoice from    = new MInvoice(GetCtx(), Recurring.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());
                            msg += invoice.GetDocumentNo();
                        }
                        else if (Recurring.GetRecurringType().Equals(MRecurring.RECURRINGTYPE_Project))
                        {
                            MProject project = MProject.CopyFrom(GetCtx(), Recurring.GetC_Project_ID(), dateDoc, Get_TrxName());
                            run.SetC_Project_ID(project.GetC_Project_ID());
                            msg += project.GetValue();
                        }
                        else if (Recurring.GetRecurringType().Equals(MRecurring.RECURRINGTYPE_GLJournalBatch))
                        {
                            MJournalBatch journal = MJournalBatch.CopyFrom(GetCtx(), Recurring.GetGL_JournalBatch_ID(), dateDoc, Get_TrxName());
                            run.SetGL_JournalBatch_ID(journal.GetGL_JournalBatch_ID());
                            msg += journal.GetDocumentNo();
                        }
                        else if (Recurring.GetRecurringType().Equals(MRecurring.RECURRINGTYPE_GLJournal))
                        {
                            MJournal Journal = MJournal.CopyFrom(GetCtx(), Recurring.GetGL_Journal_ID(), dateDoc, Get_TrxName());
                            run.SetGL_Journal_ID(Journal.GetGL_Journal_ID());
                            msg += Journal.GetDocumentNo();
                        }
                        else if (Recurring.GetRecurringType().Equals(MRecurring.RECURRINGTYPE_Payment))
                        {
                            MPayment from    = new MPayment(GetCtx(), Recurring.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@ = " + Recurring.GetRecurringType();
                        if (run.Save(Get_TrxName()))
                        {
                            Recurring.SetDateLastRun(run.GetUpdated());
                            Recurring.SetRunsRemaining(Recurring.GetRunsRemaining() - 1);
                            SetDateNextRun();
                            Recurring.Save(Get_TrxName());
                        }
                        // }
                    }
                }
            }
            DisposeVariables();
            return("");
            //  throw new NotImplementedException();
        }
        protected override string DoIt()
        {
            try
            {
                if (order_ID == 0)
                {
                    throw new ArgumentException("No Order");
                }

                MOrder from = new MOrder(GetCtx(), order_ID, Get_TrxName());

                // Check Validity date of Blanket Order.
                if (from.GetOrderValidTo() < DateTime.Now.Date)
                {
                    return(Msg.GetMsg(GetCtx(), "VIS_BlanketNotValid"));
                }

                MDocType dt = MDocType.Get(GetCtx(), from.GetC_DocType_ID());

                //Document Type against Release Order
                if (dt.GetDocumentTypeforReleases() == 0)
                {
                    return(Msg.GetMsg(GetCtx(), "VIS_ReleaseDocumentnotFound"));
                }

                if (from.GetDocStatus() == MOrder.DOCSTATUS_Drafted ||
                    from.GetDocStatus() == MOrder.DOCSTATUS_InProgress ||
                    from.GetDocStatus() == MOrder.DOCSTATUS_Voided ||
                    from.GetDocStatus() == MOrder.DOCSTATUS_Reversed)
                {
                    throw new Exception("Order Not Valid");
                }

                //Document Type against Release Order
                //MDocType dtt = MDocType.Get(GetCtx(), dt.GetDocumentTypeforReleases());
                //if (dtt == null)
                //{
                //    throw new Exception(Msg.GetMsg(GetCtx(), "VIS_ReleaseDocumentnotFound"));
                //}

                // JID_1474 if full quantity of all lines are released from blanket order and user run Release order process then system will not allow to create
                // Release order and give message: 'All quantity are released'.

                if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT SUM(qtyentered) FROM C_OrderLine WHERE C_Order_ID = " + GetRecord_ID(), null, Get_TrxName())) == 0)
                {
                    return(Msg.GetMsg(GetCtx(), "VIS_AllQtyReleased"));
                }

                //Creating Release PO/SO against blanket Orders
                MOrder rposo = MOrder.CopyFrom(from, from.GetDateAcct(),
                                               dt.GetDocumentTypeforReleases(), false, true, Get_TrxName(), false);

                rposo.SetPOReference(Util.GetValueOfString(from.GetDocumentNo()));
                rposo.Set_Value("IsBlanketTrx", false);

                // JID_0890: On Blanket Sales/Purchase Order, Create Release Purchase/Sales Order Process was not working.
                //rposo.SetOrig_Order_ID(order_ID);
                rposo.SetC_Order_Blanket(GetRecord_ID()); //Set Blanket Order ID to release SO/PO
                rposo.SetIsSOTrx(dt.IsSOTrx());
                //Set Same Document Sequence FROM Document type-- for Document is Number Controlled
                //Commented because its creating same document no
                //if (dtt.IsDocNoControlled() && dtt.GetDocNoSequence_ID() > 0)
                //{
                //    MSequence seq = new MSequence(GetCtx(), dtt.GetDocNoSequence_ID(), Get_TrxName());
                //    rposo.SetDocumentNo(Util.GetValueOfString(seq.GetCurrentNext()));
                //}
                if (!rposo.Save(Get_TrxName()))
                {
                    ValueNamePair pp = VLogger.RetrieveError();
                    throw new Exception("Could not create new Release Order. " + (pp != null ? pp.GetName() : ""));
                }
                string msg = Msg.GetMsg(GetCtx(), "OrderCreatedSuccessfully");
                return(msg + ":" + rposo.GetDocumentNo());
            }
            catch (Exception e)
            {
                //JID_1474 : if exception is found then we have to rollback and return that exception as suggested by Puneet and Gagandeep kaur
                Get_TrxName().Rollback();
                _log.SaveError("Could not create new Release Order", e);
                return(e.Message);
            }
        }
        /// <summary>
        /// Perform Process.
        /// </summary>
        /// <returns>Message (clear text)</returns>
        protected override String DoIt()
        {
            //log.Info("C_Order_ID=" + _C_Order_ID
            //    + ", C_DocType_ID=" + _C_DocType_ID
            //    + ", CloseDocument=" + _IsCloseDocument);
            //if (_C_Order_ID == 0)
            //{
            //    throw new ArgumentException("No Order");
            //}
            //MDocType dt = MDocType.Get(GetCtx(), _C_DocType_ID);
            //if (dt.Get_ID() == 0)
            //{
            //    throw new ArgumentException("No DocType");
            //}
            //if (_DateDoc == null)
            //{
            //    _DateDoc = DateTime.Now;
            //  //Util.GetValueOfDateTime(new DateTime(CommonFunctions.CurrentTimeMillis()));
            //}
            ////
            //MOrder from = new MOrder(GetCtx(), _C_Order_ID, Get_Trx());
            //MOrder newOrder = MOrder.CopyFrom(from, _DateDoc,
            //    dt.GetC_DocType_ID(), false, true, null);		//	copy ASI
            //newOrder.SetC_DocTypeTarget_ID(_C_DocType_ID);
            //bool OK = newOrder.Save ();
            //if (!OK)
            //{
            //    throw new Exception("Could not create new Order");
            //}
            ////
            //if (_IsCloseDocument)
            //{
            //    MOrder original = new MOrder(GetCtx(), _C_Order_ID, Get_Trx());
            //    original.SetDocAction(MOrder.DOCACTION_Complete);
            //    original.ProcessIt(MOrder.DOCACTION_Complete);
            //    original.Save();
            //    original.SetDocAction(MOrder.DOCACTION_Close);
            //    original.ProcessIt(MOrder.DOCACTION_Close);
            //    original.Save();
            //}
            ////
            //return dt.GetName() + ": " + newOrder.GetDocumentNo();


            log.Info("C_Order_ID=" + _C_Order_ID
                     + ", C_DocType_ID=" + _C_DocType_ID
                     + ", CloseDocument=" + _IsCloseDocument);
            if (_C_Order_ID == 0)
            {
                throw new ArgumentException("No Order");
            }
            VAdvantage.Model.MDocType dt = VAdvantage.Model.MDocType.Get(GetCtx(), _C_DocType_ID);
            if (dt.Get_ID() == 0)
            {
                throw new ArgumentException("No DocType");
            }
            if (_DateDoc == null)
            {
                _DateDoc = Util.GetValueOfDateTime(DateTime.Now);
            }
            //
            VAdvantage.Model.MOrder from = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx());
            MOrder newOrder = MOrder.CopyFrom(from, _DateDoc,
                                              dt.GetC_DocType_ID(), false, true, null, true);//Pass optional parameter as True that we are going to create Order from Create Sales Order Process on Sales Quotation window---Neha

            newOrder.SetC_DocTypeTarget_ID(_C_DocType_ID);
            //Update New Order Refrence From Sales Qutation in Sales order
            newOrder.SetPOReference(Util.GetValueOfString(from.GetDocumentNo()));
            int C_Bpartner_ID = newOrder.GetC_BPartner_ID();

            newOrder.Set_Value("IsSalesQuotation", false);

            // Added by Bharat on 31 Jan 2018 to set Inco Term from Quotation

            if (newOrder.Get_ColumnIndex("C_IncoTerm_ID") > 0)
            {
                newOrder.SetC_IncoTerm_ID(from.GetC_IncoTerm_ID());
            }
            String sqlbp = "update c_project set c_bpartner_id=" + C_Bpartner_ID + "  where ref_order_id=" + _C_Order_ID + "";
            int    value = DB.ExecuteQuery(sqlbp, null, Get_Trx());
            bool   OK    = newOrder.Save();

            if (!OK)
            {
                throw new Exception("Could not create new Order");
            }
            if (OK)
            {
                string sql          = "select C_Project_id from c_project where c_order_id = " + from.GetC_Order_ID();
                int    C_Project_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx()));
                if (C_Project_ID != 0)
                {
                    VAdvantage.Model.X_C_Project project = new VAdvantage.Model.X_C_Project(GetCtx(), C_Project_ID, Get_Trx());
                    project.SetC_BPartner_ID(project.GetC_BPartnerSR_ID());
                    project.SetC_BPartnerSR_ID(0);
                    if (!project.Save())
                    {
                    }
                }
                from.SetRef_Order_ID(newOrder.GetC_Order_ID());
                from.Save();
                int bp = newOrder.GetC_BPartner_ID();
                VAdvantage.Model.X_C_BPartner prosp = new VAdvantage.Model.X_C_BPartner(GetCtx(), bp, Get_Trx());
                prosp.SetIsCustomer(true);
                prosp.SetIsProspect(false);
                prosp.Save();
            }

            //
            if (_IsCloseDocument)
            {
                VAdvantage.Model.MOrder original = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx());
                //Edited by Arpit Rai on 8th of Nov,2017
                if (original.GetDocStatus() != "CO") //to check if document is already completed
                {
                    original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Complete);
                    original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Complete);
                    original.Save();
                }
                //Arpit
                original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Close);
                original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Close);
                original.Save();
            }
            //
            return(Msg.GetMsg(GetCtx(), "OrderCreatedSuccessfully") + " - " + dt.GetName() + ": " + newOrder.GetDocumentNo());
        }
예제 #5
0
        }       //	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