/// <summary>
        /// Perrform Process.
        /// </summary>
        /// <returns>Message (clear text)</returns>
        protected override String DoIt()
        {
            log.Info("C_Order_ID=" + _C_Order_ID + ", C_Invoice_ID=" + _C_Invoice_ID);
            if (_C_Order_ID == 0 && _C_Invoice_ID == 0)
            {
                throw new Exception("Nothing to do");
            }

            String retValue = "";

            if (_C_Order_ID != 0)
            {
                MOrder       order    = new MOrder(GetCtx(), _C_Order_ID, Get_TrxName());
                Decimal      oldPrice = order.GetGrandTotal();
                MOrderLine[] lines    = order.GetLines();
                for (int i = 0; i < lines.Length; i++)
                {
                    lines[i].SetPrice(order.GetM_PriceList_ID());
                    lines[i].Save();
                }
                order = new MOrder(GetCtx(), _C_Order_ID, Get_TrxName());
                Decimal newPrice = order.GetGrandTotal();
                retValue = order.GetDocumentNo() + ":  " + oldPrice + " -> " + newPrice;
            }
            if (_C_Invoice_ID != 0)
            {
                MInvoice       invoice  = new MInvoice(GetCtx(), _C_Invoice_ID, null);
                Decimal        oldPrice = invoice.GetGrandTotal();
                MInvoiceLine[] lines    = invoice.GetLines(false);
                for (int i = 0; i < lines.Length; i++)
                {
                    lines[i].SetPrice(invoice.GetM_PriceList_ID(), invoice.GetC_BPartner_ID());
                    lines[i].Save();
                }
                invoice = new MInvoice(GetCtx(), _C_Invoice_ID, null);
                Decimal newPrice = invoice.GetGrandTotal();
                if (retValue.Length > 0)
                {
                    retValue += Env.NL;
                }
                retValue += invoice.GetDocumentNo() + ":  " + oldPrice + " -> " + newPrice;
            }
            //
            return(retValue);
        }
        protected override String DoIt()
        {
            MInvoice obj = new MInvoice(GetCtx(), GetRecord_ID(), Get_Trx());

            // get Precision for rounding
            MCurrency currency = new MCurrency(GetCtx(), obj.GetC_Currency_ID(), Get_Trx());

            precision = currency.GetStdPrecision();

            MInvoiceLine[] lines = obj.GetLines();

            if (_IsCLearDiscount == "N")
            {
                if (_DiscountAmt == 0 && _DiscountPercent == 0)
                {
                    return(Msg.GetMsg(GetCtx(), "PlsSelAtlstOneField"));
                }

                if (_DiscountAmt != 0 && _DiscountPercent != 0)
                {
                    return(Msg.GetMsg(GetCtx(), "PlsSelOneField"));
                }

                // get amount on which we have to apply discount
                subTotal = obj.GetTotalLines();

                // when we are giving discount in terms of amount, then we have to calculate discount in term of percentage
                discountPercentageOnTotalAmount = GetDiscountPercentageOnTotal(subTotal, _DiscountAmt, precision);

                for (int i = 0; i < lines.Length; i++)
                {
                    MInvoiceLine ln = lines[i];
                    // this value represent discount on line net amount
                    discountAmountOnTotal = GetDiscountAmountOnTotal(ln.GetLineNetAmt(), discountPercentageOnTotalAmount != 0 ? discountPercentageOnTotalAmount : _DiscountPercent);

                    // this value represent discount on unit price of 1 qty
                    discountAmountOnTotal = Decimal.Round(Decimal.Divide(discountAmountOnTotal, ln.GetQtyEntered()), precision);

                    ln.SetAmountAfterApplyDiscount(Decimal.Add(ln.GetAmountAfterApplyDiscount(), discountAmountOnTotal));
                    ln.SetPriceActual(Decimal.Round(Decimal.Subtract(ln.GetPriceActual(), discountAmountOnTotal), precision));
                    ln.SetPriceEntered(Decimal.Round(Decimal.Subtract(ln.GetPriceEntered(), discountAmountOnTotal), precision));
                    // set tax amount as 0, so that on before save we calculate tax again on discounted price
                    ln.SetTaxAmt(0);
                    if (!ln.Save(Get_TrxName()))
                    {
                        Rollback();
                        ValueNamePair pp = VLogger.RetrieveError();
                        log.Info("ApplyDiscountInvoiceVendor : Not Saved. Error Value : " + pp.GetValue() + " , Error Name : " + pp.GetName());
                        throw new Exception(Msg.GetMsg(GetCtx(), "DiscNotApplied"));
                    }
                }
                return(Msg.GetMsg(GetCtx(), "DiscAppliedSuccess"));
            }
            else
            {
                for (int i = 0; i < lines.Length; i++)
                {
                    MInvoiceLine ln = lines[i];
                    ln.SetPriceEntered(Decimal.Add(ln.GetPriceEntered(), ln.GetAmountAfterApplyDiscount()));
                    ln.SetPriceActual(Decimal.Add(ln.GetPriceActual(), ln.GetAmountAfterApplyDiscount()));
                    ln.SetAmountAfterApplyDiscount(0);
                    ln.SetTaxAmt(0);
                    if (!ln.Save(Get_TrxName()))
                    {
                        Rollback();
                        ValueNamePair pp = VLogger.RetrieveError();
                        log.Info("ApplyDiscountInvoiceVendor : Not Saved. Error Value : " + pp.GetValue() + " , Error Name : " + pp.GetName());
                        throw new Exception(Msg.GetMsg(GetCtx(), "DiscNotCleared"));
                    }
                }
                return(Msg.GetMsg(GetCtx(), "DiscClearedSuccessfully"));
            }
        }
        /// <summary>
        ///     Create Shipment
        /// </summary>
        /// <returns>info</returns>
        protected override String DoIt()
        {
            //log.info("C_Invoice_ID=" + _C_Invoice_ID
            //    + ", M_Warehouse_ID=" + _M_Warehouse_ID
            //    + ", C_DocType_ID=" + _C_DocType_ID);
            if (_C_Invoice_ID == 0)
            {
                throw new ArgumentException("@NotFound@ @C_Invoice_ID@");
            }
            if (_M_Warehouse_ID == 0)
            {
                throw new ArgumentException("@NotFound@ @M_Warehouse_ID@");
            }
            //
            MInvoice invoice = new MInvoice(GetCtx(), _C_Invoice_ID, Get_Trx());

            if (invoice.Get_ID() == 0)
            {
                throw new ArgumentException("@NotFound@ @C_Invoice_ID@");
            }
            if (!MInvoice.DOCSTATUS_Completed.Equals(invoice.GetDocStatus()))
            {
                throw new ArgumentException("@InvoiceCreateDocNotCompleted@");
            }
            MDocType dt = MDocType.Get(GetCtx(), _C_DocType_ID);

            if (invoice.IsSOTrx() != dt.IsSOTrx() ||
                invoice.IsReturnTrx() != dt.IsReturnTrx())
            {
                throw new ArgumentException("@C_DocType_ID@ <> @C_Invoice_ID@");
            }

            //*****************************Vikas  1 Dec 2015  *********************************
            //Case Msg Not Showing Proper
            MInOut ship = null;
            MOrder ord  = new MOrder(GetCtx(), invoice.GetC_Order_ID(), null);

            if (ord.GetC_BPartner_ID() > 0)
            {
                ship = new MInOut(invoice, _C_DocType_ID, null, _M_Warehouse_ID);
                // Change by Mohit Asked by Amardeep sir 02/03/2016
                ship.SetPOReference(invoice.GetPOReference());
                // End
                if (!ship.Save())
                {
                    return(GetRetrievedError(ship, "@SaveError@ Receipt"));
                    // throw new ArgumentException("@SaveError@ Receipt");
                }
            }
            else
            {
                return(GetRetrievedError(ship, "InvoiceNotLinkedWithPO"));
                //throw new ArgumentException("@InvoiceNotLinkedWithPO@");
            }

            /*
             * MInOut ship = new MInOut(invoice, _C_DocType_ID, null, _M_Warehouse_ID);
             * if (!ship.Save())
             * {
             *     throw new ArgumentException("@SaveError@ Receipt");
             * }
             */
            //************************END*****************************************
            MInvoiceLine[] invoiceLines = invoice.GetLines(false);
            for (int i = 0; i < invoiceLines.Length; i++)
            {
                MInvoiceLine invoiceLine = invoiceLines[i];

                MProduct product = invoiceLine.GetProduct();
                //	Nothing to Deliver

                // Get the lines of Invoice based on the setting taken on Tenant to allow non item Product
                if (Util.GetValueOfString(GetCtx().GetContext("$AllowNonItem")).Equals("N") &&
                    ((product != null && product.GetProductType() != MProduct.PRODUCTTYPE_Item) || invoiceLine.GetC_Charge_ID() != 0))
                {
                    continue;
                }

                MInOutLine sLine = new MInOutLine(ship);
                //JID_1679 Generate Receipt from Invoice(Vendor) for remaining quantity
                //decimal movementqty = 0;
                //if (invoiceLine.GetC_OrderLine_ID() != 0)
                //{
                //    decimal? res = 0;
                //    movementqty = Util.GetValueOfDecimal(DB.ExecuteScalar(@" select (QtyOrdered-sum(MovementQty))   from C_OrderLine ol Inner join M_InOutLine il on il.C_orderline_ID= ol.C_Orderline_Id "
                //            + " WHERE il.C_OrderLine_ID =" + invoiceLine.GetC_OrderLine_ID() + "group by QtyOrdered", null, Get_Trx()));
                //    // in case of partial receipt
                //    if (invoiceLine.GetQtyInvoiced() > movementqty && movementqty != 0)
                //    {
                //        if (product.GetC_UOM_ID() != invoiceLine.GetC_UOM_ID())
                //        {
                //            res = MUOMConversion.ConvertProductTo(GetCtx(), product.GetM_Product_ID(), invoiceLine.GetC_UOM_ID(), movementqty);
                //        }
                //        sLine.SetInvoiceLine(invoiceLine, 0,    //	Locator
                //            invoice.IsSOTrx() ? (movementqty) : Env.ZERO);
                //        sLine.SetQtyEntered(res == 0 ? (movementqty) : res);
                //        sLine.SetMovementQty(movementqty);
                //    }
                //    // if QtyInvoiced is less or No Material receipt is found against the order
                //    else
                //    {
                //        sLine.SetInvoiceLine(invoiceLine, 0,    //	Locator
                //          invoice.IsSOTrx() ? invoiceLine.GetQtyInvoiced() : Env.ZERO);
                //        sLine.SetQtyEntered(invoiceLine.GetQtyEntered());
                //        sLine.SetMovementQty(invoiceLine.GetQtyInvoiced());
                //    }
                //}
                //else
                //{
                sLine.SetInvoiceLine(invoiceLine, 0,            //	Locator
                                     invoice.IsSOTrx() ? invoiceLine.GetQtyInvoiced() : Env.ZERO);
                sLine.SetQtyEntered(invoiceLine.GetQtyEntered());
                sLine.SetMovementQty(invoiceLine.GetQtyInvoiced());
                //}
                if (invoice.IsCreditMemo())
                {
                    sLine.SetQtyEntered(Decimal.Negate(sLine.GetQtyEntered()));   //.negate());
                    sLine.SetMovementQty(Decimal.Negate(sLine.GetMovementQty())); //.negate());
                }
                if (!sLine.Save())
                {
                    ship.Get_Trx().Rollback();
                    //if (movementqty == 0)
                    //{
                    //    _processMsg += ", LineNo: " + invoiceLine.GetLine() + Msg.GetMsg(GetCtx(), "MRIsAlreadyCreated");
                    //    return _processMsg;
                    //}
                    //else
                    //{
                    return(GetRetrievedError(sLine, "@SaveError@ @M_InOutLine_ID@"));
                    //}
                    // throw new ArgumentException("@SaveError@ @M_InOutLine_ID@");
                }
                invoiceLine.SetM_InOutLine_ID(sLine.GetM_InOutLine_ID());
                //  _processMsg+= ", LineNo: "+invoiceLine.GetLine()+Msg.GetMsg(GetCtx(), "MRCreatedWithDocNo" + ship.GetDocumentNo());
                if (!invoiceLine.Save())
                {
                    return(GetRetrievedError(invoiceLine, "@SaveError@ @C_InvoiceLine_ID@"));
                    //throw new ArgumentException("@SaveError@ @C_InvoiceLine_ID@");
                }
            }
            return(ship.GetDocumentNo());
        }
Beispiel #4
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);
        }
Beispiel #5
0
        /// <summary>
        ///     Create Shipment
        /// </summary>
        /// <returns>info</returns>
        protected override String DoIt()
        {
            //log.info("C_Invoice_ID=" + _C_Invoice_ID
            //    + ", M_Warehouse_ID=" + _M_Warehouse_ID
            //    + ", C_DocType_ID=" + _C_DocType_ID);
            if (_C_Invoice_ID == 0)
            {
                throw new ArgumentException("@NotFound@ @C_Invoice_ID@");
            }
            if (_M_Warehouse_ID == 0)
            {
                throw new ArgumentException("@NotFound@ @M_Warehouse_ID@");
            }
            //
            MInvoice invoice = new MInvoice(GetCtx(), _C_Invoice_ID, null);

            if (invoice.Get_ID() == 0)
            {
                throw new ArgumentException("@NotFound@ @C_Invoice_ID@");
            }
            if (!MInvoice.DOCSTATUS_Completed.Equals(invoice.GetDocStatus()))
            {
                throw new ArgumentException("@InvoiceCreateDocNotCompleted@");
            }
            MDocType dt = MDocType.Get(GetCtx(), _C_DocType_ID);

            if (invoice.IsSOTrx() != dt.IsSOTrx() ||
                invoice.IsReturnTrx() != dt.IsReturnTrx())
            {
                throw new ArgumentException("@C_DocType_ID@ <> @C_Invoice_ID@");
            }

            //*****************************Vikas  1 Dec 2015  *********************************
            //Case Msg Not Showing Proper
            MInOut ship = null;
            MOrder ord  = new MOrder(GetCtx(), invoice.GetC_Order_ID(), null);

            if (ord.GetC_BPartner_ID() > 0)
            {
                ship = new MInOut(invoice, _C_DocType_ID, null, _M_Warehouse_ID);
                // Change by Mohit Asked by Amardeep sir 02/03/2016
                ship.SetPOReference(invoice.GetPOReference());
                // End
                if (!ship.Save())
                {
                    return(GetRetrievedError(ship, "@SaveError@ Receipt"));
                    // throw new ArgumentException("@SaveError@ Receipt");
                }
            }
            else
            {
                return(GetRetrievedError(ship, "InvoiceNotLinkedWithPO"));
                //throw new ArgumentException("@InvoiceNotLinkedWithPO@");
            }

            /*
             * MInOut ship = new MInOut(invoice, _C_DocType_ID, null, _M_Warehouse_ID);
             * if (!ship.Save())
             * {
             *     throw new ArgumentException("@SaveError@ Receipt");
             * }
             */
            //************************END*****************************************
            MInvoiceLine[] invoiceLines = invoice.GetLines(false);
            for (int i = 0; i < invoiceLines.Length; i++)
            {
                MInvoiceLine invoiceLine = invoiceLines[i];

                MProduct product = invoiceLine.GetProduct();
                //	Nothing to Deliver

                // Get the lines of Invoice based on the setting taken on Tenant to allow non item Product
                if (Util.GetValueOfString(GetCtx().GetContext("$AllowNonItem")).Equals("N") &&
                    ((product != null && product.GetProductType() != MProduct.PRODUCTTYPE_Item) || invoiceLine.GetC_Charge_ID() != 0))
                {
                    continue;
                }

                MInOutLine sLine = new MInOutLine(ship);
                sLine.SetInvoiceLine(invoiceLine, 0,    //	Locator
                                     invoice.IsSOTrx() ? invoiceLine.GetQtyInvoiced() : Env.ZERO);
                sLine.SetQtyEntered(invoiceLine.GetQtyEntered());
                sLine.SetMovementQty(invoiceLine.GetQtyInvoiced());
                if (invoice.IsCreditMemo())
                {
                    sLine.SetQtyEntered(Decimal.Negate(sLine.GetQtyEntered()));   //.negate());
                    sLine.SetMovementQty(Decimal.Negate(sLine.GetMovementQty())); //.negate());
                }
                if (!sLine.Save())
                {
                    return(GetRetrievedError(sLine, "@SaveError@ @M_InOutLine_ID@"));
                    //throw new ArgumentException("@SaveError@ @M_InOutLine_ID@");
                }
                //
                invoiceLine.SetM_InOutLine_ID(sLine.GetM_InOutLine_ID());
                if (!invoiceLine.Save())
                {
                    return(GetRetrievedError(invoiceLine, "@SaveError@ @C_InvoiceLine_ID@"));
                    //throw new ArgumentException("@SaveError@ @C_InvoiceLine_ID@");
                }
            }
            return(ship.GetDocumentNo());
        }
Beispiel #6
0
        /// <summary>
        ///     Create Shipment
        /// </summary>
        /// <returns>info</returns>
        protected override String DoIt()
        {
            //log.info("C_Invoice_ID=" + _C_Invoice_ID
            //    + ", M_Warehouse_ID=" + _M_Warehouse_ID
            //    + ", C_DocType_ID=" + _C_DocType_ID);
            if (_C_Invoice_ID == 0)
            {
                throw new ArgumentException("@NotFound@ @C_Invoice_ID@");
            }
            if (_M_Warehouse_ID == 0)
            {
                throw new ArgumentException("@NotFound@ @M_Warehouse_ID@");
            }
            //
            MInvoice invoice = new MInvoice(GetCtx(), _C_Invoice_ID, null);

            if (invoice.Get_ID() == 0)
            {
                throw new ArgumentException("@NotFound@ @C_Invoice_ID@");
            }
            if (!MInvoice.DOCSTATUS_Completed.Equals(invoice.GetDocStatus()))
            {
                throw new ArgumentException("@InvoiceCreateDocNotCompleted@");
            }
            MDocType dt = MDocType.Get(GetCtx(), _C_DocType_ID);

            if (invoice.IsSOTrx() != dt.IsSOTrx() ||
                invoice.IsReturnTrx() != dt.IsReturnTrx())
            {
                throw new ArgumentException("@C_DocType_ID@ <> @C_Invoice_ID@");
            }
            //
            MInOut ship = new MInOut(invoice, _C_DocType_ID, null, _M_Warehouse_ID);

            if (!ship.Save())
            {
                throw new ArgumentException("@SaveError@ Receipt");
            }
            //
            MInvoiceLine[] invoiceLines = invoice.GetLines(false);
            for (int i = 0; i < invoiceLines.Length; i++)
            {
                MInvoiceLine invoiceLine = invoiceLines[i];
                MInOutLine   sLine       = new MInOutLine(ship);
                sLine.SetInvoiceLine(invoiceLine, 0,    //	Locator
                                     invoice.IsSOTrx() ? invoiceLine.GetQtyInvoiced() : Env.ZERO);
                sLine.SetQtyEntered(invoiceLine.GetQtyEntered());
                sLine.SetMovementQty(invoiceLine.GetQtyInvoiced());
                if (invoice.IsCreditMemo())
                {
                    sLine.SetQtyEntered(Decimal.Negate(sLine.GetQtyEntered()));   //.negate());
                    sLine.SetMovementQty(Decimal.Negate(sLine.GetMovementQty())); //.negate());
                }
                if (!sLine.Save())
                {
                    throw new ArgumentException("@SaveError@ @M_InOutLine_ID@");
                }
                //
                invoiceLine.SetM_InOutLine_ID(sLine.GetM_InOutLine_ID());
                if (!invoiceLine.Save())
                {
                    throw new ArgumentException("@SaveError@ @C_InvoiceLine_ID@");
                }
            }
            return(ship.GetDocumentNo());
        }