/// <summary>
        /// GetInvoiceBatchLine
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public Dictionary <String, String> GetInvoiceBatchLine(Ctx ctx, string fields)
        {
            string[] paramValue = fields.Split(',');
            int      C_InvoiceBatchLine_ID;
            //decimal Qty;
            //bool isSOTrx;
            Dictionary <String, String> retDic = new Dictionary <string, string>();

            //Assign parameter value
            C_InvoiceBatchLine_ID = Util.GetValueOfInt(paramValue[0].ToString());
            //End Assign parameter value

            MInvoiceBatchLine last = new MInvoiceBatchLine(ctx, C_InvoiceBatchLine_ID, null);

            //	Need to Increase when different DocType or BP
            retDic["C_DocType_ID"]  = last.GetC_DocType_ID().ToString();
            retDic["C_BPartner_ID"] = last.GetC_BPartner_ID().ToString();
            retDic["DocumentNo"]    = last.GetDocumentNo();
            //	New Number
            return(retDic);
        }
Beispiel #2
0
        /// <summary>
        /// Process Invoice Batch
        /// </summary>
        /// <returns></returns>
        protected override String DoIt()
        {
            log.Info("C_InvoiceBatch_ID=" + _C_InvoiceBatch_ID + ", DocAction=" + _DocAction);
            if (_C_InvoiceBatch_ID == 0)
            {
                throw new Exception("C_InvoiceBatch_ID = 0");
            }
            MInvoiceBatch batch = new MInvoiceBatch(GetCtx(), _C_InvoiceBatch_ID, Get_TrxName());

            if (batch.Get_ID() == 0)
            {
                throw new Exception("@NotFound@: @C_InvoiceBatch_ID@ - " + _C_InvoiceBatch_ID);
            }
            if (batch.IsProcessed())
            {
                throw new Exception("@Processed@");
            }
            //
            if (Signum(batch.GetControlAmt()) != 0 && batch.GetControlAmt().CompareTo(batch.GetDocumentAmt()) != 0)
            {
                throw new Exception("@ControlAmt@ <> @DocumentAmt@");
            }
            //
            MInvoiceBatchLine[] lines = batch.GetLines(false);
            for (int i = 0; i < lines.Length; i++)
            {
                MInvoiceBatchLine line = lines[i];
                if (line.GetC_Invoice_ID() != 0 || line.GetC_InvoiceLine_ID() != 0)
                {
                    continue;
                }

                if ((_oldDocumentNo != null &&
                     !_oldDocumentNo.Equals(line.GetDocumentNo())) ||
                    _oldC_BPartner_ID != line.GetC_BPartner_ID() ||
                    _oldC_BPartner_Location_ID != line.GetC_BPartner_Location_ID())
                {
                    CompleteInvoice();
                }
                //	New Invoice
                if (_invoice == null)
                {
                    _invoice = new MInvoice(batch, line);
                    if (!_invoice.Save())
                    {
                        return(GetRetrievedError(_invoice, "Cannot save Invoice"));
                    }
                    //throw new Exception("Cannot save Invoice");
                    //
                    _oldDocumentNo             = line.GetDocumentNo();
                    _oldC_BPartner_ID          = line.GetC_BPartner_ID();
                    _oldC_BPartner_Location_ID = line.GetC_BPartner_Location_ID();
                }

                if (line.IsTaxIncluded() != _invoice.IsTaxIncluded())
                {
                    return(GetRetrievedError(line, "Line " + line.GetLine() + " TaxIncluded inconsistent"));
                    //	rollback
                    // throw new Exception("Line " + line.GetLine() + " TaxIncluded inconsistent");
                }

                //	Add Line
                MInvoiceLine invoiceLine = new MInvoiceLine(_invoice);
                invoiceLine.SetDescription(line.GetDescription());
                invoiceLine.SetC_Charge_ID(line.GetC_Charge_ID());
                invoiceLine.SetQty(line.GetQtyEntered());       // Entered/Invoiced
                invoiceLine.SetPrice(line.GetPriceEntered());
                invoiceLine.SetC_Tax_ID(line.GetC_Tax_ID());
                invoiceLine.SetTaxAmt(line.GetTaxAmt());
                invoiceLine.SetLineNetAmt(line.GetLineNetAmt());
                invoiceLine.SetLineTotalAmt(line.GetLineTotalAmt());
                if (!invoiceLine.Save())
                {
                    return(GetRetrievedError(invoiceLine, "Cannot save Invoice Line"));
                    //	rollback
                    // throw new Exception("Cannot save Invoice Line");
                }

                //	Update Batch Line
                line.SetC_Invoice_ID(_invoice.GetC_Invoice_ID());
                line.SetC_InvoiceLine_ID(invoiceLine.GetC_InvoiceLine_ID());
                line.Save();
            }   //	for all lines

            CompleteInvoice();
            //
            batch.SetProcessed(true);
            batch.Save();

            return("#" + _count);
        }       //	doIt