コード例 #1
0
        /// <summary>
        /// Create Commission Detail
        /// </summary>
        /// <param name="sql">sql statement</param>
        /// <param name="comAmt">parent</param>
        private void CreateDetail(String sql, MCommissionAmt comAmt)
        {
            IDataReader idr = null;

            try
            {
                SqlParameter[] param = new SqlParameter[3];
                param[0] = new SqlParameter("@clientid", m_com.GetAD_Client_ID());
                param[1] = new SqlParameter("@sdate", p_StartDate.Date);
                param[2] = new SqlParameter("@edate", m_EndDate.Date);

                idr = DataBase.DB.ExecuteReader(sql, param, Get_Trx());
                while (idr.Read())
                {
                    //	CommissionAmount, C_Currency_ID, Amt, Qty,
                    MCommissionDetail cd = new MCommissionDetail(comAmt,
                                                                 Utility.Util.GetValueOfInt(idr[0]), Utility.Util.GetValueOfDecimal(idr[1]), Utility.Util.GetValueOfDecimal(idr[2]));

                    //	C_OrderLine_ID, C_InvoiceLine_ID,
                    cd.SetLineIDs(Utility.Util.GetValueOfInt(idr[3]), Utility.Util.GetValueOfInt(idr[4]));

                    //	Reference, Info,
                    String s = idr[5].ToString();
                    if (s != null)
                    {
                        cd.SetReference(s);
                    }
                    s = idr[6].ToString();
                    if (s != null)
                    {
                        cd.SetInfo(s);
                    }

                    //	Date
                    DateTime?date = Utility.Util.GetValueOfDateTime(idr[7]);
                    cd.SetConvertedAmt(date);

                    //
                    if (!cd.Save())             //	creates memory leak
                    {
                        idr.Close();
                        throw new ArgumentException("CommissionCalc - Detail Not saved");
                    }
                }
                idr.Close();
            }
            catch (Exception e)
            {
                idr.Close();
                log.Log(Level.SEVERE, "CreateDetail", e);
            }
        }
コード例 #2
0
        /// <summary>
        /// Perform Process.
        /// </summary>
        /// <returns>Message (variables are parsed)</returns>
        protected override String DoIt()
        {
            log.Info("doIt - C_CommissionRun_ID=" + GetRecord_ID());
            //	Load Data
            MCommissionRun comRun = new MCommissionRun(GetCtx(), GetRecord_ID(), Get_Trx());

            if (comRun.Get_ID() == 0)
            {
                throw new ArgumentException("CommissionAPInvoice - No Commission Run");
            }
            if (Env.ZERO.CompareTo(comRun.GetGrandTotal()) == 0)
            {
                throw new ArgumentException("@GrandTotal@ = 0");
            }
            MCommission com = new MCommission(GetCtx(), comRun.GetC_Commission_ID(), Get_Trx());

            if (com.Get_ID() == 0)
            {
                throw new ArgumentException("CommissionAPInvoice - No Commission");
            }
            if (com.GetC_Charge_ID() == 0)
            {
                throw new ArgumentException("CommissionAPInvoice - No Charge on Commission");
            }
            MBPartner bp = new MBPartner(GetCtx(), com.GetC_BPartner_ID(), Get_Trx());

            if (bp.Get_ID() == 0)
            {
                throw new ArgumentException("CommissionAPInvoice - No BPartner");
            }

            //	Create Invoice
            MInvoice invoice = new MInvoice(GetCtx(), 0, null);

            invoice.SetClientOrg(com.GetAD_Client_ID(), com.GetAD_Org_ID());
            invoice.SetC_DocTypeTarget_ID(MDocBaseType.DOCBASETYPE_APINVOICE);  //	API
            invoice.SetBPartner(bp);
            //	invoice.setDocumentNo (comRun.getDocumentNo());		//	may cause unique constraint
            invoice.SetSalesRep_ID(GetAD_User_ID());    //	caller
            //
            if (com.GetC_Currency_ID() != invoice.GetC_Currency_ID())
            {
                throw new ArgumentException("CommissionAPInvoice - Currency of PO Price List not Commission Currency");
            }
            //
            if (!invoice.Save())
            {
                throw new Exception("CommissionAPInvoice - cannot save Invoice");
            }

            //	Create Invoice Line
            MInvoiceLine iLine = new MInvoiceLine(invoice);

            iLine.SetC_Charge_ID(com.GetC_Charge_ID());
            iLine.SetQty(1);
            iLine.SetPrice(comRun.GetGrandTotal());
            iLine.SetTax();
            if (!iLine.Save())
            {
                throw new Exception("CommissionAPInvoice - cannot save Invoice Line");
            }
            //
            return("@C_Invoice_ID@ = " + invoice.GetDocumentNo());
        }
コード例 #3
0
        /// <summary>
        /// Perform Process.
        /// </summary>
        /// <returns>Message (variables are parsed)</returns>
        protected override String DoIt()
        {
            log.Info("doIt - C_CommissionRun_ID=" + GetRecord_ID());
            //	Load Data
            MCommissionRun comRun = new MCommissionRun(GetCtx(), GetRecord_ID(), Get_Trx());

            if (comRun.Get_ID() == 0)
            {
                throw new ArgumentException("CommissionAPInvoice - No Commission Run");
            }
            if (Env.ZERO.CompareTo(comRun.GetGrandTotal()) == 0)
            {
                throw new ArgumentException("@GrandTotal@ = 0");
            }
            MCommission com = new MCommission(GetCtx(), comRun.GetC_Commission_ID(), Get_Trx());

            if (com.Get_ID() == 0)
            {
                throw new ArgumentException("CommissionAPInvoice - No Commission");
            }
            if (com.GetC_Charge_ID() == 0)
            {
                throw new ArgumentException("CommissionAPInvoice - No Charge on Commission");
            }
            MBPartner bp = new MBPartner(GetCtx(), com.GetC_BPartner_ID(), Get_Trx());

            if (bp.Get_ID() == 0)
            {
                throw new ArgumentException("CommissionAPInvoice - No BPartner");
            }

            //	Create Invoice
            MInvoice invoice = new MInvoice(GetCtx(), 0, null);

            invoice.SetClientOrg(com.GetAD_Client_ID(), com.GetAD_Org_ID());
            invoice.SetC_DocTypeTarget_ID(MDocBaseType.DOCBASETYPE_APINVOICE);  //	API
            invoice.SetBPartner(bp);

            // JID_0101: When we generate the AP invoice from Commission run window, its giving price list error.
            if (invoice.GetM_PriceList_ID() == 0)
            {
                string sql = "SELECT M_PriceList_ID FROM M_PriceList WHERE IsActive = 'Y' AND AD_Client_ID = " + com.GetAD_Client_ID() + " AND AD_Org_ID = " + com.GetAD_Org_ID()
                             + " AND IsDefault='Y' AND IsSOPriceList='N'";
                int pricelist = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx()));
                if (pricelist == 0)
                {
                    pricelist = MPriceList.GetDefault(GetCtx(), false).Get_ID();
                }
                if (pricelist > 0)
                {
                    invoice.SetM_PriceList_ID(pricelist);
                }
            }
            //	invoice.setDocumentNo (comRun.getDocumentNo());		//	may cause unique constraint
            invoice.SetSalesRep_ID(GetAD_User_ID());    //	caller
            //
            if (com.GetC_Currency_ID() != invoice.GetC_Currency_ID())
            {
                throw new ArgumentException("CommissionAPInvoice - Currency of PO Price List not Commission Currency");
            }
            //
            if (!invoice.Save())
            {
                //return GetReterivedError(invoice, "CommissionAPInvoice - cannot save Invoice");
                throw new Exception("CommissionAPInvoice - cannot save Invoice");
            }

            //	Create Invoice Line
            MInvoiceLine iLine = new MInvoiceLine(invoice);

            iLine.SetC_Charge_ID(com.GetC_Charge_ID());
            iLine.SetQty(1);
            iLine.SetPrice(comRun.GetGrandTotal());
            iLine.SetTax();
            if (!iLine.Save())
            {
                //return GetReterivedError(iLine, "CommissionAPInvoice - cannot save Invoice Line");
                throw new Exception("CommissionAPInvoice - cannot save Invoice Line");
            }
            //
            return("@C_Invoice_ID@ = " + invoice.GetDocumentNo());
        }