Esempio n. 1
0
        /// <summary>
        /// Create Invoice Line
        /// </summary>
        /// <param name="C_Invoice_ID">invoice</param>
        /// <param name="C_Currency_ID">currency</param>
        /// <param name="GrandTotal">total</param>
        /// <param name="Open">amount</param>
        /// <param name="DaysDue">days due</param>
        /// <param name="IsInDispute">in dispute</param>
        /// <param name="C_BPartner_ID">bp</param>
        /// <param name="timesDunned">number of dunnings</param>
        /// <param name="daysAfterLast">days after last dunning</param>
        private void CreateInvoiceLine(int C_Invoice_ID, int C_Currency_ID,
                                       Decimal GrandTotal, Decimal Open,
                                       int DaysDue, bool IsInDispute,
                                       int C_BPartner_ID, int timesDunned, int daysAfterLast)
        {
            MDunningRunEntry entry = _run.GetEntry(C_BPartner_ID, _C_Currency_ID, _SalesRep_ID);

            if (entry.Get_ID() == 0)
            {
                if (!entry.Save())
                {
                    throw new Exception("Cannot save MDunningRunEntry");
                }
            }
            //
            MDunningRunLine line = new MDunningRunLine(entry);

            line.SetInvoice(C_Invoice_ID, C_Currency_ID, GrandTotal, Open,
                            new Decimal(0), DaysDue, IsInDispute, timesDunned,
                            daysAfterLast);
            if (!line.Save())
            {
                throw new Exception("Cannot save MDunningRunLine");
            }
        }
        /// <summary>
        /// Create Invoice Line on run tab of dunning run window.
        /// </summary>
        /// <param name="C_Invoice_ID">Invoice ID.</param>
        /// <param name="C_Currency_ID">Currency ID.</param>
        /// <param name="GrandTotal">Grand Total.</param>
        /// <param name="Open">Amount.</param>
        /// <param name="DaysDue">Days Due.</param>
        /// <param name="IsInDispute">In Dispute.</param>
        /// <param name="C_BPartner_ID">Business Partner.</param>
        /// <param name="timesDunned">Number of times dunning occurred.</param>
        /// <param name="daysAfterLast">Days after last dunning.</param>
        private bool CreateInvoiceLine(int C_Invoice_ID, int C_Currency_ID,
                                       Decimal GrandTotal, Decimal Open,
                                       int DaysDue, bool IsInDispute,
                                       int C_BPartner_ID, int timesDunned, int daysAfterLast, int PaySchedule_ID)
        {
            MDunningRunEntry entry = _run.GetEntry(C_BPartner_ID, _C_Currency_ID, _SalesRep_ID);

            if (entry.Get_ID() == 0)
            {
                if (!entry.Save())
                {
                    // Change by mohit to pick error message from last error in mclass.
                    //throw new Exception(GetRetrievedError(entry, "Cannot save MDunningRunEntry"));
                    //throw new Exception("Cannot save MDunningRunEntry");
                    ValueNamePair vp = VLogger.RetrieveError();
                    if (vp != null)
                    {
                        log.SaveError(Msg.GetMsg(GetCtx(), "NotSaveDunRunEntry"), vp.GetName());
                    }
                    else
                    {
                        log.SaveError(Msg.GetMsg(GetCtx(), "NotSaveDunRunEntry"), "");
                    }
                    return(false);
                }
            }
            //
            MDunningRunLine line = new MDunningRunLine(entry);

            line.SetInvoice(C_Invoice_ID, C_Currency_ID, GrandTotal, Open,
                            new Decimal(0), DaysDue, IsInDispute, timesDunned,
                            daysAfterLast);
            line.SetC_InvoicePaySchedule_ID(PaySchedule_ID);
            if (!line.Save())
            {
                // Change by mohit to pick error message from last error in mclass.
                //throw new Exception(GetRetrievedError(line, "Cannot save MDunningRunLine"));
                //throw new Exception("Cannot save MDunningRunLine");
                ValueNamePair vp = VLogger.RetrieveError();
                if (vp != null)
                {
                    log.SaveError(Msg.GetMsg(GetCtx(), "NotSaveDunRunLine"), vp.GetName());
                }
                else
                {
                    log.SaveError(Msg.GetMsg(GetCtx(), "NotSaveDunRunLine"), "");
                }
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// Create Payment Line on run tab of dunning run window.
        /// </summary>
        /// <param name="C_Payment_ID">Payment ID.</param>
        /// <param name="C_Currency_ID">Currency ID.</param>
        /// <param name="PayAmt">Amount.</param>
        /// <param name="openAmt">Open.</param>
        /// <param name="C_BPartner_ID">Business Partner ID.</param>
        private bool CreatePaymentLine(int C_Payment_ID, int C_Currency_ID,
                                       Decimal PayAmt, Decimal openAmt, int C_BPartner_ID)
        {
            MDunningRunEntry entry = _run.GetEntry(C_BPartner_ID, _C_Currency_ID, _SalesRep_ID);

            if (entry.Get_ID() == 0)
            {
                if (!entry.Save())
                {
                    // Change by mohit to pick error message from last error in mclass.
                    //throw new Exception(GetRetrievedError(entry, "Cannot save MDunningRunEntry"));
                    //throw new Exception("Cannot save MDunningRunEntry");
                    //log.SaveError("Cannot save MDunningRunEntry", "");
                    ValueNamePair vp = VLogger.RetrieveError();
                    if (vp != null)
                    {
                        string val = vp.GetName();
                        log.SaveError(Msg.GetMsg(GetCtx(), "NotSaveDunRunEntry"), val);
                    }
                    else
                    {
                        log.SaveError(Msg.GetMsg(GetCtx(), "NotSaveDunRunEntry"), "");
                    }
                    return(false);
                }
            }
            //
            MDunningRunLine line = new MDunningRunLine(entry);

            line.SetPayment(C_Payment_ID, C_Currency_ID, PayAmt, openAmt);

            if (!line.Save())
            {
                // Change by mohit to pick error message from last error in mclass.
                //throw new Exception(GetRetrievedError(line, "Cannot save MDunningRunLine"));
                //throw new Exception("Cannot save MDunningRunLine");
                ValueNamePair vp = VLogger.RetrieveError();
                if (vp != null)
                {
                    log.SaveError(Msg.GetMsg(GetCtx(), "NotSaveDunRunLine"), vp.GetName());
                }
                else
                {
                    log.SaveError(Msg.GetMsg(GetCtx(), "NotSaveDunRunLine"), "");
                }
                return(false);
            }
            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Create Payment Line
        /// </summary>
        /// <param name="C_Payment_ID">payment</param>
        /// <param name="C_Currency_ID">currency</param>
        /// <param name="PayAmt">amount</param>
        /// <param name="openAmt">open</param>
        /// <param name="C_BPartner_ID">bp</param>
        private void CreatePaymentLine(int C_Payment_ID, int C_Currency_ID,
                                       Decimal PayAmt, Decimal openAmt, int C_BPartner_ID)
        {
            MDunningRunEntry entry = _run.GetEntry(C_BPartner_ID, _C_Currency_ID, _SalesRep_ID);

            if (entry.Get_ID() == 0)
            {
                if (!entry.Save())
                {
                    throw new Exception("Cannot save MDunningRunEntry");
                }
            }
            //
            MDunningRunLine line = new MDunningRunLine(entry);

            line.SetPayment(C_Payment_ID, C_Currency_ID, PayAmt, openAmt);
            if (!line.Save())
            {
                throw new Exception("Cannot save MDunningRunLine");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Process
        /// </summary>
        /// <returns>info</returns>
        protected override String DoIt()
        {
            log.Info("C_DunningRun_ID=" + _C_DunningRun_ID + ",R_MailText_ID=" + _R_MailText_ID
                     + ", EmailPDF=" + _EMailPDF + ",IsOnlyIfBPBalance=" + _IsOnlyIfBPBalance);

            //	Need to have Template
            if (_EMailPDF && _R_MailText_ID == 0)
            {
                throw new Exception("@NotFound@: @R_MailText_ID@");
            }
            String    subject = "";
            MMailText mText   = null;

            if (_EMailPDF)
            {
                mText = new MMailText(GetCtx(), _R_MailText_ID, Get_TrxName());
                if (_EMailPDF && mText.Get_ID() == 0)
                {
                    throw new Exception("@NotFound@: @R_MailText_ID@ - " + _R_MailText_ID);
                }
                subject = mText.GetMailHeader();
            }
            //
            MDunningRun run = new MDunningRun(GetCtx(), _C_DunningRun_ID, Get_TrxName());

            if (run.Get_ID() == 0)
            {
                throw new Exception("@NotFound@: @C_DunningRun_ID@ - " + _C_DunningRun_ID);
            }
            //	Print Format on Dunning Level
            MDunningLevel level = new MDunningLevel(GetCtx(), run.GetC_DunningLevel_ID(), Get_TrxName());
            //MPrintFormat format = MPrintFormat.Get(GetCtx(), level.GetDunning_PrintFormat_ID(), false);

            MClient client = MClient.Get(GetCtx());

            int count  = 0;
            int errors = 0;

            MDunningRunEntry[] entries = run.GetEntries(false);
            for (int i = 0; i < entries.Length; i++)
            {
                MDunningRunEntry entry = entries[i];
                if (_IsOnlyIfBPBalance && Env.Signum(entry.GetAmt()) <= 0)
                {
                    continue;
                }
                //	To BPartner
                MBPartner bp = new MBPartner(GetCtx(), entry.GetC_BPartner_ID(), Get_TrxName());
                if (bp.Get_ID() == 0)
                {
                    AddLog(entry.Get_ID(), null, null, "@NotFound@: @C_BPartner_ID@ " + entry.GetC_BPartner_ID());
                    errors++;
                    continue;
                }
                //	To User
                MUser to = new MUser(GetCtx(), entry.GetAD_User_ID(), Get_TrxName());
                if (_EMailPDF)
                {
                    if (to.Get_ID() == 0)
                    {
                        AddLog(entry.Get_ID(), null, null, "@NotFound@: @AD_User_ID@ - " + bp.GetName());
                        errors++;
                        continue;
                    }
                    else if (to.GetEMail() == null || to.GetEMail().Length == 0)
                    {
                        AddLog(entry.Get_ID(), null, null, "@NotFound@: @EMail@ - " + to.GetName());
                        errors++;
                        continue;
                    }
                }
                //	BP Language
                //Language language =Language.getLoginLanguage();		//	Base Language
                Language language = Env.GetLoginLanguage(GetCtx());

                String tableName = "C_Dunning_Header_v";
                if (client.IsMultiLingualDocument())
                {
                    tableName += "t";
                    String AD_Language = bp.GetAD_Language();
                    if (AD_Language != null)
                    {
                        //language =language.getLanguage(AD_Language);
                    }
                }
                // format.SetLanguage(language);
                // format.SetTranslationLanguage(language);
                //	query
                Query query = new Query(tableName);
                query.AddRestriction("C_DunningRunEntry_ID", Query.EQUAL,
                                     entry.GetC_DunningRunEntry_ID());

                //	Engine
                //PrintInfo info = new PrintInfo(
                //    bp.GetName(),
                //    X_C_DunningRunEntry.Table_ID,
                //    entry.GetC_DunningRunEntry_ID(),
                //    entry.GetC_BPartner_ID());
                //info.SetDescription(bp.GetName() + ", Amt=" + entry.GetAmt());
                //ReportEngine re = new ReportEngine(GetCtx(), format, query, info);
                bool printed = false;
                if (_EMailPDF)
                {
                    EMail email = client.CreateEMail(to.GetEMail(), to.GetName(), null, null);
                    if (email == null || !email.IsValid())
                    {
                        AddLog(entry.Get_ID(), null, null,
                               "@RequestActionEMailError@ Invalid EMail: " + to);
                        errors++;
                        continue;
                    }
                    mText.SetUser(to);  //	variable context
                    mText.SetBPartner(bp);
                    mText.SetPO(entry);
                    String message = mText.GetMailText(true);
                    if (mText.IsHtml())
                    {
                        email.SetMessageHTML(mText.GetMailHeader(), message);
                    }
                    else
                    {
                        email.SetSubject(mText.GetMailHeader());
                        email.SetMessageText(message);
                    }
                    //
                    //File attachment = re.GetPDF(File.createTempFile("Dunning", ".pdf"));
                    //log.Fine(to + " - " + attachment);
                    //email.AddAttachment(attachment);
                    //
                    String    msg = email.Send();
                    MUserMail um  = new MUserMail(mText, entry.GetAD_User_ID(), email);
                    um.Save();
                    if (msg.Equals(EMail.SENT_OK))
                    {
                        AddLog(entry.Get_ID(), null, null,
                               bp.GetName() + " @RequestActionEMailOK@");
                        count++;
                        printed = true;
                    }
                    else
                    {
                        AddLog(entry.Get_ID(), null, null,
                               bp.GetName() + " @RequestActionEMailError@ " + msg);
                        errors++;
                    }
                }
                else
                {
                    //re.print();
                    count++;
                    printed = true;
                }
                if (printed)
                {
                    entry.SetProcessed(true);
                    entry.Save();
                    DunningLevelConsequences(level, entry);
                }
            }   //	for all dunning letters
            if (errors == 0)
            {
                run.SetProcessed(true);
                run.Save();
            }

            if (_EMailPDF)
            {
                return("@Sent@=" + count + " - @Errors@=" + errors);
            }
            return("@Printed@=" + count);
        }