Esempio n. 1
0
        /// <summary>
        /// Load Invoice Line
        /// </summary>
        /// <param name="journal"></param>
        /// <returns>DocLine Array</returns>
        private DocLine[] LoadLines(MJournal journal)
        {
            List <DocLine> list = new List <DocLine>();

            MJournalLine[] lines = journal.GetLines(false);
            for (int i = 0; i < lines.Length; i++)
            {
                MJournalLine line    = lines[i];
                DocLine      docLine = new DocLine(line, this);
                //  --  Source Amounts
                docLine.SetAmount(line.GetAmtSourceDr(), line.GetAmtSourceCr());
                //  --  Converted Amounts
                docLine.SetConvertedAmt(_C_AcctSchema_ID, line.GetAmtAcctDr(), line.GetAmtAcctCr());
                //  --  Account
                MAccount account = line.GetAccount();
                docLine.SetAccount(account);
                //  -- Quantity
                docLine.SetQty(line.GetQty(), false);
                // -- Date
                docLine.SetDateAcct(journal.GetDateAcct());
                //	--	Organization of Line was set to Org of Account
                list.Add(docLine);
            }
            //	Return Array
            int size = list.Count;

            DocLine[] dls = new DocLine[size];
            dls = list.ToArray();
            return(dls);
        }
        /// <summary>
        /// Load Invoice Line
        /// </summary>
        /// <param name="inout">shipment/receipt</param>
        /// <returns>DocLine Array</returns>
        private DocLine[] LoadLines(MInOut inout)
        {
            List <DocLine> list = new List <DocLine>();

            MInOutLine[] lines = inout.GetLines(false);
            for (int i = 0; i < lines.Length; i++)
            {
                MInOutLine line = lines[i];
                if (line.IsDescription() ||
                    line.GetM_Product_ID() == 0 ||
                    Env.Signum(line.GetMovementQty()) == 0)
                {
                    log.Finer("Ignored: " + line);
                    continue;
                }
                //	PO Matching
                if (_MatchRequirementR.Equals(X_M_InOut.MATCHREQUIREMENTR_PurchaseOrder) ||
                    _MatchRequirementR.Equals(X_M_InOut.MATCHREQUIREMENTR_PurchaseOrderAndInvoice))
                {
                    Decimal poDiff = line.GetMatchPODifference();
                    if (Env.Signum(poDiff) != 0)
                    {
                        _matchProblem += "; Line=" + line.GetLine()
                                         + " PO Match diff=" + poDiff;
                    }
                    else if (!line.IsMatchPOPosted())
                    {
                        _matchProblem += "; PO Match not posted for Line=" + line.GetLine();
                    }
                }
                //	Inv Matching
                else if (_MatchRequirementR.Equals(X_M_InOut.MATCHREQUIREMENTR_Invoice) ||
                         _MatchRequirementR.Equals(X_M_InOut.MATCHREQUIREMENTR_PurchaseOrderAndInvoice))
                {
                    Decimal invDiff = line.GetMatchInvDifference();
                    if (Env.Signum(invDiff) != 0)
                    {
                        _matchProblem += "; Line=" + line.GetLine()
                                         + " PO Match diff=" + invDiff;
                    }
                    else if (!line.IsMatchInvPosted())
                    {
                        _matchProblem += "; Inv Match not posted for Line=" + line.GetLine();
                    }
                }

                DocLine docLine = new DocLine(line, this);
                Decimal Qty     = line.GetMovementQty();
                docLine.SetQty(Qty, GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_MATERIALDELIVERY));    //  sets Trx and Storage Qty
                //
                log.Fine(docLine.ToString());
                list.Add(docLine);
            }

            //	Return Array
            DocLine[] dls = new DocLine[list.Count];
            dls = list.ToArray();
            return(dls);
        }
        /// <summary>
        /// Load Document Details
        /// </summary>
        /// <returns>error message or null</returns>
        public override String LoadDocumentDetails()
        {
            SetC_Currency_ID(NO_CURRENCY);
            _issue = (MProjectIssue)GetPO();
            SetDateDoc(_issue.GetMovementDate());
            SetDateAcct(_issue.GetMovementDate());

            //	Pseudo Line
            _line = new DocLine(_issue, this);
            _line.SetQty(_issue.GetMovementQty(), true);    //  sets Trx and Storage Qty

            //	Pseudo Line Check
            if (_line.GetM_Product_ID() == 0)
            {
                log.Warning(_line.ToString() + " - No Product");
            }
            log.Fine(_line.ToString());
            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// Load Invoice Line
        /// </summary>
        /// <param name="move"></param>
        /// <returns>document lines (DocLine_Material)</returns>
        private DocLine[] LoadLines(MMovement move)
        {
            List <DocLine> list = new List <DocLine>();

            MMovementLine[] lines = move.GetLines(false);
            for (int i = 0; i < lines.Length; i++)
            {
                MMovementLine line    = lines[i];
                DocLine       docLine = new DocLine(line, this);
                docLine.SetQty(line.GetMovementQty(), false);
                //
                log.Fine(docLine.ToString());
                list.Add(docLine);
            }

            //	Return Array
            DocLine[] dls = new DocLine[list.Count];
            dls = list.ToArray();
            return(dls);
        }
Esempio n. 5
0
        /// <summary>
        /// Load Requisition Lines
        /// </summary>
        /// <param name="req">requisition</param>
        /// <returns>DocLine Array</returns>
        private DocLine[] LoadLines(MRequisition req)
        {
            List <DocLine> list = new List <DocLine>();

            MRequisitionLine[] lines = req.GetLines();
            for (int i = 0; i < lines.Length; i++)
            {
                MRequisitionLine line    = lines[i];
                DocLine          docLine = new DocLine(line, this);
                Decimal          Qty     = line.GetQty();
                docLine.SetQty(Qty, false);
                //	Decimal PriceActual =
                line.GetPriceActual();
                Decimal LineNetAmt = line.GetLineNetAmt();
                docLine.SetAmount(LineNetAmt);   // DR
                list.Add(docLine);
            }
            // Return Array
            DocLine[] dls = new DocLine[list.Count];
            dls = list.ToArray();
            return(dls);
        }
Esempio n. 6
0
        /// <summary>
        /// Load Invoice Line
        /// </summary>
        /// <param name="inventory"></param>
        /// <returns>DocLine Array</returns>
        private DocLine[] LoadLines(MInventory inventory)
        {
            List <DocLine> list = new List <DocLine>();

            MInventoryLine[] lines = inventory.GetLines(false);
            for (int i = 0; i < lines.Length; i++)
            {
                MInventoryLine line = lines[i];
                //	nothing to post
                if (line.GetQtyBook().CompareTo(line.GetQtyCount()) == 0 &&
                    Env.Signum(line.GetQtyInternalUse()) == 0)
                {
                    continue;
                }
                //
                DocLine docLine = new DocLine(line, this);
                Decimal Qty     = line.GetQtyInternalUse();
                if (Env.Signum(Qty) != 0)
                {
                    Qty = Decimal.Negate(Qty);          //	Internal Use entered positive
                }
                else
                {
                    Decimal QtyBook  = line.GetQtyBook();
                    Decimal QtyCount = line.GetQtyCount();
                    Qty = Decimal.Subtract(QtyCount, QtyBook);
                }
                docLine.SetQty(Qty, false);             // -5 => -5
                //
                log.Fine(docLine.ToString());
                list.Add(docLine);
            }

            //	Return Array
            DocLine[] dls = new DocLine[list.Count];
            dls = list.ToArray();
            return(dls);
        }
Esempio n. 7
0
        /// <summary>
        /// Load Invoice Line
        /// </summary>
        /// <param name="journal"></param>
        /// <returns>DocLine Array</returns>
        private DocLine[] LoadLines(MJournal journal)
        {
            MAcctSchema    mSc  = new MAcctSchema(GetCtx(), _C_AcctSchema_ID, null);
            List <DocLine> list = new List <DocLine>();

            MJournalLine[] lines = journal.GetLines(false);
            record_Id = lines[0].GetGL_Journal_ID();

            for (int i = 0; i < lines.Length; i++)
            {
                MJournalLine line = lines[i];

                if (line.GetElementType() == null)
                {
                    DocLine docLine = new DocLine(line, this);
                    //  --  Source Amounts
                    docLine.SetAmount(line.GetAmtAcctDr(), line.GetAmtAcctCr());
                    //  --  Converted Amounts
                    // no need to update converted amount here
                    //docLine.SetConvertedAmt(_C_AcctSchema_ID, line.GetAmtAcctDr(), line.GetAmtAcctCr());
                    //  --  Account
                    MAccount account = line.GetAccount();
                    docLine.SetAccount(account);
                    //  -- Quantity
                    docLine.SetQty(line.GetQty(), false);
                    // -- Date
                    docLine.SetDateAcct(journal.GetDateAcct());
                    //	--	Organization of Line was set to Org of Account
                    list.Add(docLine);
                }
                else
                {
                    string  sql = "SELECT * FROM GL_LineDimension WHERE GL_JournalLine_ID=" + line.Get_ID();
                    DataSet ds  = DB.ExecuteDataset(sql);
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    {
                        for (int m = 0; m < ds.Tables[0].Rows.Count; m++)
                        {
                            DataRow            dr   = ds.Tables[0].Rows[m];
                            X_GL_LineDimension lDim = new X_GL_LineDimension(GetCtx(), dr, null);

                            DocLine docLine = new DocLine(lDim, this);
                            //  --  Source Amounts


                            decimal cRate = line.GetCurrencyRate();
                            if (cRate == 0)
                            {
                                cRate = 1;
                            }
                            decimal amtAcctCr = 0;
                            decimal amtAcctDr = 0;

                            //MAcctSchema mSc = new MAcctSchema(GetCtx(), _C_AcctSchema_ID, null);


                            if (line.GetAmtSourceDr() != 0)
                            {
                                amtAcctDr = lDim.GetAmount() * cRate;
                                docLine.SetAmount(amtAcctDr, 0);
                                amtAcctDr = Decimal.Round(amtAcctDr, mSc.GetStdPrecision());
                            }
                            else
                            {
                                amtAcctCr = lDim.GetAmount() * cRate;
                                docLine.SetAmount(0, amtAcctCr);
                                amtAcctCr = Decimal.Round(amtAcctCr, mSc.GetStdPrecision());
                            }
                            //  --  Converted Amounts
                            // no need to update converted amount here
                            //docLine.SetConvertedAmt(_C_AcctSchema_ID, amtAcctDr, amtAcctCr);
                            //  --  Account
                            MAccount account = line.GetAccount();


                            docLine.SetAccount(account);
                            //  -- Quantity
                            docLine.SetQty(lDim.GetQty(), false);
                            // -- Date
                            docLine.SetDateAcct(journal.GetDateAcct());

                            // -- User Dimension
                            docLine = SetUserDimension(lDim, docLine);

                            //	--	Organization of Line was set to Org of Account
                            list.Add(docLine);
                        }
                    }
                }
            }
            //	Return Array
            int size = list.Count;

            DocLine[] dls = new DocLine[size];
            dls = list.ToArray();
            return(dls);
        }
Esempio n. 8
0
        /// <summary>
        /// Load Invoice Line
        /// </summary>
        /// <param name="invoice">invoice</param>
        /// <returns>DocLine Array</returns>
        private DocLine[] LoadLines(MInvoice invoice)
        {
            List <DocLine> list = new List <DocLine>();

            //
            MInvoiceLine[] lines = invoice.GetLines(false);
            for (int i = 0; i < lines.Length; i++)
            {
                MInvoiceLine line = lines[i];
                if (line.IsDescription())
                {
                    continue;
                }
                DocLine docLine = new DocLine(line, this);
                //	Qty
                Decimal Qty = line.GetQtyInvoiced();
                bool    cm  = GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_ARCREDITMEMO) ||
                              GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_APCREDITMEMO);
                docLine.SetQty(cm ? Decimal.Negate(Qty) : Qty, invoice.IsSOTrx());
                //
                Decimal LineNetAmt = line.GetLineNetAmt();
                Decimal PriceList  = line.GetPriceList();
                int     C_Tax_ID   = docLine.GetC_Tax_ID();
                //	Correct included Tax
                if (IsTaxIncluded() && C_Tax_ID != 0)
                {
                    MTax tax = MTax.Get(GetCtx(), C_Tax_ID);
                    if (!tax.IsZeroTax())
                    {
                        Decimal LineNetAmtTax = tax.CalculateTax(LineNetAmt, true, GetStdPercision());
                        log.Fine("LineNetAmt=" + LineNetAmt + " - Tax=" + LineNetAmtTax);
                        LineNetAmt = Decimal.Subtract(LineNetAmt, LineNetAmtTax);
                        for (int t = 0; t < _taxes.Length; t++)
                        {
                            if (_taxes[t].GetC_Tax_ID() == C_Tax_ID)
                            {
                                _taxes[t].AddIncludedTax(LineNetAmtTax);
                                break;
                            }
                        }
                        Decimal PriceListTax = tax.CalculateTax(PriceList, true, GetStdPercision());
                        PriceList = Decimal.Subtract(PriceList, PriceListTax);
                    }
                }                                              //	correct included Tax

                docLine.SetAmount(LineNetAmt, PriceList, Qty); //	qty for discount calc
                if (docLine.IsItem())
                {
                    _allLinesService = false;
                }
                else
                {
                    _allLinesItem = false;
                }
                //
                log.Fine(docLine.ToString());
                list.Add(docLine);
            }

            //	Convert to Array
            DocLine[] dls = new DocLine[list.Count];
            dls = list.ToArray();

            //	Included Tax - make sure that no difference
            if (IsTaxIncluded())
            {
                for (int i = 0; i < _taxes.Length; i++)
                {
                    if (_taxes[i].IsIncludedTaxDifference())
                    {
                        Decimal diff = _taxes[i].GetIncludedTaxDifference();
                        for (int j = 0; j < dls.Length; j++)
                        {
                            if (dls[j].GetC_Tax_ID() == _taxes[i].GetC_Tax_ID())
                            {
                                dls[j].SetLineNetAmtDifference(diff);
                                break;
                            }
                        } //	for all lines
                    }     //	tax difference
                }         //	for all taxes
            }             //	Included Tax difference

            //	Return Array
            return(dls);
        }
Esempio n. 9
0
        public override List <Fact> CreateFacts(MAcctSchema as1)
        {
            List <Fact>          facts   = new List <Fact>();
            MProductCategoryAcct pca     = null;
            String costingMethodOfSchema = as1.GetCostingMethod();
            String costingLevelOfSchema  = as1.GetCostingLevel();

            // Get the costing method and the costing level of the product Category for the current accounting schema.
            if (mpc != null)
            {
                pca = MProductCategoryAcct.Get(GetCtx(), mpc.GetM_Product_Category_ID(), as1.GetC_AcctSchema_ID(), null);
                if (pca.GetCostingMethod() != null)
                {
                    costingMethod = pca.GetCostingMethod();
                }
                else
                {
                    costingMethod = costingMethodOfSchema;
                }

                if (pca.GetCostingLevel() != null)
                {
                    costingLevel = pca.GetCostingLevel();
                }
                else
                {
                    costingLevel = costingLevelOfSchema;
                }

                // proceed only if the costing method is standard
                if (!costingMethod.Equals(X_C_AcctSchema.COSTINGMETHOD_StandardCosting))
                {
                    return(facts);
                }
            }

            Fact fact = new Fact(this, as1, Fact.POST_Actual);

            FactLine dr = null;
            FactLine cr = null;

            for (int i = 0; i < _lines.Length; i++)
            {
                DocLine line = _lines[i];

                if (mpc == null)
                {
                    pca = MProductCategoryAcct.Get(GetCtx(), MProduct.Get(GetCtx(), line.GetM_Product_ID()).
                                                   GetM_Product_Category_ID(),
                                                   as1.GetC_AcctSchema_ID(), null);
                    if (pca.GetCostingMethod() != null)
                    {
                        costingMethod = pca.GetCostingMethod();
                    }
                    else
                    {
                        costingMethod = costingMethodOfSchema;
                    }

                    if (pca.GetCostingLevel() != null)
                    {
                        costingLevel = pca.GetCostingLevel();
                    }
                    else
                    {
                        costingLevel = costingLevelOfSchema;
                    }

                    // proceed only if the costing method is standard
                    if (!costingMethod.Equals(X_C_AcctSchema.COSTINGMETHOD_StandardCosting))
                    {
                        return(facts);
                    }
                }
                Decimal currentCost = Env.ZERO;
                Decimal oldCost     = Env.ZERO;
                Decimal Qty         = Env.ZERO;
                String  sql         = " SELECT Sum(CurrentCostPrice), Sum(LastCostPrice), Sum(CurrentQty)"
                                      + " FROM M_Cost WHERE M_Product_ID = " + line.GetM_Product_ID()
                                      + " AND C_AcctSchema_ID = " + as1.GetC_AcctSchema_ID()
                                      + " AND M_CostElement_ID = " + m_ce.GetM_CostElement_ID()
                                      + " AND M_CostType_ID = " + as1.GetM_CostType_ID()
                                      + " AND AD_Client_ID = " + GetAD_Client_ID();
                if (costingLevel.Equals(X_C_AcctSchema.COSTINGLEVEL_Client))
                {
                    sql += " AND AD_Org_ID = 0"
                           + " AND M_AttributeSetInstance_ID  = 0";
                }
                else if (costingLevel.Equals(X_C_AcctSchema.COSTINGLEVEL_Organization))
                {
                    sql += " AND M_AttributeSetInstance_ID  = 0";
                }
                else if (costingLevel.Equals(X_C_AcctSchema.COSTINGLEVEL_BatchLot))
                {
                    sql += " AND AD_Org_ID = 0";
                }

                IDataReader idr = null;
                try
                {
                    idr = DB.ExecuteReader(sql, null, GetTrx());
                    while (idr.Read())
                    {
                        currentCost = Util.GetValueOfDecimal(idr[0]);
                        oldCost     = Util.GetValueOfDecimal(idr[1]);
                        Qty         = Util.GetValueOfDecimal(idr[2]);
                        line.SetQty(Qty, costupdate.IsSOTrx());

                        Decimal PriceCost = Decimal.Subtract(currentCost, oldCost);
                        Decimal amt       = Env.ZERO;
                        if (Env.Signum(PriceCost) != 0)
                        {
                            amt = Decimal.Multiply(Qty, PriceCost);
                        }

                        line.SetAmount(amt);

                        if (Env.Signum(amt) == 0)
                        {
                            continue;
                        }
                        MAccount db_acct, cr_acct;

                        /* Decide the Credit and Debit Accounts */
                        if (Env.Signum(amt) == 1)
                        {
                            db_acct = line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1);
                            cr_acct = line.GetAccount(ProductCost.ACCTTYPE_P_CostAdjustment, as1);
                        }
                        else
                        {
                            cr_acct = line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1);
                            db_acct = line.GetAccount(ProductCost.ACCTTYPE_P_CostAdjustment, as1);
                        }

                        /* Create Credit and Debit lines*/
                        dr = fact.CreateLine(line, db_acct, as1.GetC_Currency_ID(), Math.Abs(amt), null);
                        if (dr == null)
                        {
                            log.SaveError("NoProductCosts", "No Product Costs");
                            return(null);
                        }

                        cr = fact.CreateLine(line, cr_acct, as1.GetC_Currency_ID(), null, Math.Abs(amt));
                        if (cr == null)
                        {
                            log.SaveError("NoProductCosts", "No Product Costs");
                            return(null);
                        }
                    }
                    idr.Close();
                }
                catch (Exception e)
                {
                    log.Log(Level.SEVERE, sql, e);
                }
                finally
                {
                    if (idr != null)
                    {
                        idr.Close();
                        idr = null;
                    }
                }
            }
            facts.Add(fact);
            return(facts);
        }
Esempio n. 10
0
        /// <summary>
        /// Load Invoice Line
        /// </summary>
        /// <param name="prod">production</param>
        /// <returns> DoaLine Array</returns>
        private DocLine[] LoadLines(X_M_Production prod)
        {
            List <DocLine> list = new List <DocLine>();
            //	Production
            //	-- ProductionPlan
            //	-- -- ProductionLine	- the real level
            String sqlPP = "SELECT * FROM M_ProductionPlan pp "
                           + "WHERE pp.M_Production_ID=@param1 "
                           + "ORDER BY pp.Line";
            IDataReader idrPP = null;

            String sqlPL = "SELECT * FROM M_ProductionLine pl "
                           + "WHERE pl.M_ProductionPlan_ID=@param2 "
                           + "ORDER BY pl.Line";
            IDataReader idrPL = null;

            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@param1", Get_ID());
                idrPP    = DataBase.DB.ExecuteReader(sqlPP, param, GetTrx());
                //idrPP.setInt(1, get_ID());
                //ResultSet rsPP = idrPP.executeQuery();
                while (idrPP.Read())
                {
                    int M_Product_ID        = Utility.Util.GetValueOfInt(idrPP["M_Product_ID"]);
                    int M_ProductionPlan_ID = Utility.Util.GetValueOfInt(idrPP["M_ProductionPlan_ID"]);
                    //
                    try
                    {
                        param    = new SqlParameter[1];
                        param[0] = new SqlParameter("@param2", M_ProductionPlan_ID);
                        idrPL    = DataBase.DB.ExecuteReader(sqlPL, param, GetTrx());
                        //idrPL.setInt(1, M_ProductionPlan_ID);
                        //ResultSet rsPL = idrPL.executeQuery();
                        while (idrPL.Read())
                        {
                            X_M_ProductionLine line = new X_M_ProductionLine(GetCtx(), idrPL, GetTrx());
                            if (Env.Signum(line.GetMovementQty()) == 0)
                            {
                                log.Info("LineQty=0 - " + line);
                                continue;
                            }
                            DocLine docLine = new DocLine(line, this);
                            docLine.SetQty(line.GetMovementQty(), false);
                            //	Identify finished BOM Product
                            docLine.SetProductionBOM(line.GetM_Product_ID() == M_Product_ID);
                            //
                            log.Fine(docLine.ToString());
                            list.Add(docLine);
                        }
                        idrPL.Close();
                    }
                    catch (Exception ee)
                    {
                        if (idrPL != null)
                        {
                            idrPL.Close();
                            idrPL = null;
                        }
                        log.Log(Level.SEVERE, sqlPL, ee);
                    }
                }
                idrPP.Close();
            }
            catch (Exception e)
            {
                if (idrPP != null)
                {
                    idrPP.Close();
                    idrPP = null;
                }
                log.Log(Level.SEVERE, sqlPP, e);
            }
            //	Return Array
            DocLine[] dl = new DocLine[list.Count];
            dl = list.ToArray();
            return(dl);
        }
Esempio n. 11
0
        /// <summary>
        /// Load Invoice Line
        /// </summary>
        /// <param name="order">order</param>
        /// <returns>DocLine Array</returns>
        private DocLine[] LoadLines(MOrder order)
        {
            List <DocLine> list = new List <DocLine>();

            MOrderLine[] lines = order.GetLines();
            for (int i = 0; i < lines.Length; i++)
            {
                MOrderLine line    = lines[i];
                DocLine    docLine = new DocLine(line, this);
                Decimal    Qty     = line.GetQtyOrdered();
                docLine.SetQty(Qty, order.IsSOTrx());
                //
                //	Decimal PriceActual = line.getPriceActual();
                Decimal?PriceCost = null;
                if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_PURCHASEORDER))   //	PO
                {
                    PriceCost = line.GetPriceCost();
                }
                Decimal?LineNetAmt = null;
                if (PriceCost != null && Env.Signum(PriceCost.Value) != 0)
                {
                    LineNetAmt = Decimal.Multiply(Qty, PriceCost.Value);
                }
                else
                {
                    LineNetAmt = line.GetLineNetAmt();
                }
                docLine.SetAmount(LineNetAmt);  //	DR
                Decimal PriceList = line.GetPriceList();
                int     C_Tax_ID  = docLine.GetC_Tax_ID();
                //	Correct included Tax
                if (IsTaxIncluded() && C_Tax_ID != 0)
                {
                    MTax tax = MTax.Get(GetCtx(), C_Tax_ID);
                    if (!tax.IsZeroTax())
                    {
                        Decimal LineNetAmtTax = tax.CalculateTax(LineNetAmt.Value, true, GetStdPrecision());
                        log.Fine("LineNetAmt=" + LineNetAmt + " - Tax=" + LineNetAmtTax);
                        LineNetAmt = Decimal.Subtract(LineNetAmt.Value, LineNetAmtTax);
                        for (int t = 0; t < _taxes.Length; t++)
                        {
                            if (_taxes[t].GetC_Tax_ID() == C_Tax_ID)
                            {
                                _taxes[t].AddIncludedTax(LineNetAmtTax);
                                break;
                            }
                        }
                        Decimal PriceListTax = tax.CalculateTax(PriceList, true, GetStdPrecision());
                        PriceList = Decimal.Subtract(PriceList, PriceListTax);
                    }
                }       //	correct included Tax

                docLine.SetAmount(LineNetAmt, PriceList, Qty);
                list.Add(docLine);
            }

            //	Return Array
            DocLine[] dl = new DocLine[list.Count];
            dl = list.ToArray();
            return(dl);
        }
Esempio n. 12
0
        /// <summary>
        /// Get Commitments
        /// </summary>
        /// <param name="doc">document</param>
        /// <param name="maxQty">Qty invoiced/matched</param>
        /// <param name="C_InvoiceLine_ID">invoice line</param>
        /// <returns>commitments (order lines)</returns>
        protected static DocLine[] GetCommitments(Doc doc, Decimal maxQty, int C_InvoiceLine_ID)
        {
            int precision = -1;
            //
            List <DocLine> list = new List <DocLine>();
            String         sql  = "SELECT * FROM C_OrderLine ol "
                                  + "WHERE EXISTS "
                                  + "(SELECT * FROM C_InvoiceLine il "
                                  + "WHERE il.C_OrderLine_ID=ol.C_OrderLine_ID"
                                  + " AND il.C_InvoiceLine_ID=" + C_InvoiceLine_ID + ")"
                                  + " OR EXISTS "
                                  + "(SELECT * FROM M_MatchPO po "
                                  + "WHERE po.C_OrderLine_ID=ol.C_OrderLine_ID"
                                  + " AND po.C_InvoiceLine_ID=" + C_InvoiceLine_ID + ")";
            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, null);
                while (idr.Read())
                {
                    if (Env.Signum(maxQty) == 0)
                    {
                        continue;
                    }
                    MOrderLine line    = new MOrderLine(doc.GetCtx(), idr, null);
                    DocLine    docLine = new DocLine(line, doc);
                    //	Currency
                    if (precision == -1)
                    {
                        doc.SetC_Currency_ID(docLine.GetC_Currency_ID());
                        precision = MCurrency.GetStdPrecision(doc.GetCtx(), docLine.GetC_Currency_ID());
                    }
                    //	Qty
                    Decimal Qty = Math.Max(line.GetQtyOrdered(), maxQty);
                    docLine.SetQty(Qty, false);
                    //
                    Decimal PriceActual = line.GetPriceActual();
                    Decimal PriceCost   = line.GetPriceCost();
                    Decimal?LineNetAmt  = null;
                    if (Env.Signum(PriceCost) != 0)
                    {
                        LineNetAmt = Decimal.Multiply(Qty, PriceCost);
                    }
                    else if (Qty.Equals(maxQty))
                    {
                        LineNetAmt = line.GetLineNetAmt();
                    }
                    else
                    {
                        LineNetAmt = Decimal.Multiply(Qty, PriceActual);
                    }
                    maxQty = Decimal.Subtract(maxQty, Qty);

                    docLine.SetAmount(LineNetAmt);      //	DR
                    Decimal PriceList = line.GetPriceList();
                    int     C_Tax_ID  = docLine.GetC_Tax_ID();
                    //	Correct included Tax
                    if (C_Tax_ID != 0 && line.GetParent().IsTaxIncluded())
                    {
                        MTax tax = MTax.Get(doc.GetCtx(), C_Tax_ID);
                        if (!tax.IsZeroTax())
                        {
                            Decimal LineNetAmtTax = tax.CalculateTax(LineNetAmt.Value, true, precision);
                            _log.Fine("LineNetAmt=" + LineNetAmt + " - Tax=" + LineNetAmtTax);
                            LineNetAmt = Decimal.Subtract(LineNetAmt.Value, LineNetAmtTax);
                            Decimal PriceListTax = tax.CalculateTax(PriceList, true, precision);
                            PriceList = Decimal.Subtract(PriceList, PriceListTax);
                        }
                    }   //	correct included Tax

                    docLine.SetAmount(LineNetAmt, PriceList, Qty);
                    list.Add(docLine);
                }
                idr.Close();
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
                _log.Log(Level.SEVERE, sql, e);
            }


            //	Return Array
            DocLine[] dl = new DocLine[list.Count];
            dl = list.ToArray();
            return(dl);
        }
Esempio n. 13
0
        /// <summary>
        /// Load Requisitions
        /// </summary>
        /// <returns>requisition lines of Order</returns>
        private DocLine[] LoadRequisitions()
        {
            MOrder order = (MOrder)GetPO();

            MOrderLine[] oLines            = order.GetLines();
            Dictionary <int, Decimal> qtys = new Dictionary <int, Decimal>();

            for (int i = 0; i < oLines.Length; i++)
            {
                MOrderLine line = oLines[i];
                qtys.Add(Utility.Util.GetValueOfInt(line.GetC_OrderLine_ID()), line.GetQtyOrdered());
            }
            //
            List <DocLine> list = new List <DocLine>();
            String         sql  = "SELECT * FROM M_RequisitionLine rl "
                                  + "WHERE EXISTS (SELECT * FROM C_Order o "
                                  + " INNER JOIN C_OrderLine ol ON (o.C_Order_ID=ol.C_Order_ID) "
                                  + "WHERE ol.C_OrderLine_ID=rl.C_OrderLine_ID"
                                  + " AND o.C_Order_ID=" + order.GetC_Order_ID() + ") "
                                  + "ORDER BY rl.C_OrderLine_ID";
            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, null);
                while (idr.Read())
                {
                    MRequisitionLine line    = new MRequisitionLine(GetCtx(), idr, null);
                    DocLine          docLine = new DocLine(line, this);
                    //	Quantity - not more then OrderLine
                    //	Issue: Split of Requisition to multiple POs & different price
                    int     key    = line.GetC_OrderLine_ID();
                    Decimal maxQty = qtys[key];
                    Decimal Qty    = Math.Max(line.GetQty(), maxQty);
                    if (Env.Signum(Qty) == 0)
                    {
                        continue;
                    }
                    docLine.SetQty(Qty, false);
                    if (qtys.ContainsKey(key))
                    {
                        qtys.Remove(key);
                    }
                    qtys.Add(key, Decimal.Subtract(maxQty, Qty));
                    //
                    Decimal PriceActual = line.GetPriceActual();
                    Decimal LineNetAmt  = line.GetLineNetAmt();
                    if (line.GetQty().CompareTo(Qty) != 0)
                    {
                        LineNetAmt = Decimal.Multiply(PriceActual, Qty);
                    }
                    docLine.SetAmount(LineNetAmt);       // DR
                    list.Add(docLine);
                }
                idr.Close();
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
                log.Log(Level.SEVERE, sql, e);
            }

            // Return Array
            DocLine[] dls = new DocLine[list.Count];
            dls = list.ToArray();
            return(dls);
        }