Ejemplo n.º 1
0
        /// <summary>
        /// GetOrder
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public Dictionary <String, String> GetOrder(Ctx ctx, string fields)
        {
            string[] paramValue = fields.ToString().Split(',');
            int      C_Order_ID;

            //Assign parameter value
            C_Order_ID = Util.GetValueOfInt(paramValue[0].ToString());
            MOrder order = new MOrder(ctx, C_Order_ID, null);
            // End Assign parameter value

            Dictionary <String, String> retDic = new Dictionary <string, string>();

            // Reset Orig Shipment
            retDic["C_BPartner_ID"]          = Util.GetValueOfString(order.GetC_BPartner_ID());
            retDic["C_BPartner_Location_ID"] = Util.GetValueOfString(order.GetC_BPartner_Location_ID());
            retDic["Bill_BPartner_ID"]       = Util.GetValueOfString(order.GetBill_BPartner_ID());
            retDic["Bill_Location_ID"]       = Util.GetValueOfString(order.GetBill_Location_ID());
            if (order.GetAD_User_ID() != 0)
            {
                retDic["AD_User_ID"] = Util.GetValueOfString(order.GetAD_User_ID());
            }
            if (order.GetBill_User_ID() != 0)
            {
                retDic["Bill_User_ID"] = Util.GetValueOfString(order.GetBill_User_ID());
            }
            retDic["M_PriceList_ID"]   = Util.GetValueOfString(order.GetM_PriceList_ID());
            retDic["PaymentRule"]      = order.GetPaymentRule();
            retDic["C_PaymentTerm_ID"] = Util.GetValueOfString(order.GetC_PaymentTerm_ID());
            //mTab.setValue ("DeliveryRule", X_C_Order.DELIVERYRULE_Manual);
            retDic["Bill_Location_ID"] = Util.GetValueOfString(order.GetBill_Location_ID());
            retDic["InvoiceRule"]      = order.GetInvoiceRule();
            retDic["PaymentRule"]      = order.GetPaymentRule();
            retDic["DeliveryViaRule"]  = order.GetDeliveryViaRule();
            retDic["FreightCostRule"]  = order.GetFreightCostRule();
            retDic["ID"]              = Util.GetValueOfString(order.Get_ID());
            retDic["DateOrdered"]     = Util.GetValueOfString(order.GetDateOrdered());
            retDic["POReference"]     = order.GetPOReference();
            retDic["AD_Org_ID"]       = Util.GetValueOfString(order.GetAD_Org_ID());
            retDic["DeliveryRule"]    = order.GetDeliveryRule();
            retDic["DeliveryViaRule"] = order.GetDeliveryViaRule();
            retDic["M_Shipper_ID"]    = Util.GetValueOfString(order.GetM_Shipper_ID());
            retDic["FreightAmt"]      = Util.GetValueOfString(order.GetFreightAmt());
            retDic["AD_OrgTrx_ID"]    = Util.GetValueOfString(order.GetAD_OrgTrx_ID());
            retDic["C_Activity_ID"]   = Util.GetValueOfString(order.GetC_Activity_ID());
            retDic["C_Campaign_ID"]   = Util.GetValueOfString(order.GetC_Campaign_ID());
            retDic["C_Project_ID"]    = Util.GetValueOfString(order.GetC_Project_ID());
            retDic["User1_ID"]        = Util.GetValueOfString(order.GetUser1_ID());
            retDic["User2_ID"]        = Util.GetValueOfString(order.GetUser2_ID());
            retDic["M_Warehouse_ID"]  = Util.GetValueOfString(order.GetM_Warehouse_ID());
            retDic["Orig_Order_ID"]   = Util.GetValueOfString(order.GetOrig_Order_ID());
            retDic["Orig_InOut_ID"]   = Util.GetValueOfString(order.GetOrig_InOut_ID());
            return(retDic);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// GetOrder
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public Dictionary <String, object> GetOrder(Ctx ctx, string fields)
        {
            string[] paramValue = fields.ToString().Split(',');
            int      C_Order_ID;

            //Assign parameter value
            C_Order_ID = Util.GetValueOfInt(paramValue[0].ToString());
            MOrder order = new MOrder(ctx, C_Order_ID, null);
            // End Assign parameter value

            Dictionary <String, object> retDic = new Dictionary <string, object>();

            // Reset Orig Shipment
            retDic["C_BPartner_ID"]          = Util.GetValueOfString(order.GetC_BPartner_ID());
            retDic["C_BPartner_Location_ID"] = Util.GetValueOfString(order.GetC_BPartner_Location_ID());
            retDic["Bill_BPartner_ID"]       = Util.GetValueOfString(order.GetBill_BPartner_ID());
            retDic["Bill_Location_ID"]       = Util.GetValueOfString(order.GetBill_Location_ID());
            if (order.GetAD_User_ID() != 0)
            {
                retDic["AD_User_ID"] = Util.GetValueOfString(order.GetAD_User_ID());
            }
            if (order.GetBill_User_ID() != 0)
            {
                retDic["Bill_User_ID"] = Util.GetValueOfString(order.GetBill_User_ID());
            }
            retDic["M_PriceList_ID"]   = Util.GetValueOfString(order.GetM_PriceList_ID());
            retDic["PaymentRule"]      = order.GetPaymentRule();
            retDic["C_PaymentTerm_ID"] = Util.GetValueOfString(order.GetC_PaymentTerm_ID());
            //mTab.setValue ("DeliveryRule", X_C_Order.DELIVERYRULE_Manual);
            retDic["Bill_Location_ID"] = Util.GetValueOfString(order.GetBill_Location_ID());
            retDic["InvoiceRule"]      = order.GetInvoiceRule();
            retDic["PaymentRule"]      = order.GetPaymentRule();
            retDic["DeliveryViaRule"]  = order.GetDeliveryViaRule();
            retDic["FreightCostRule"]  = order.GetFreightCostRule();
            retDic["ID"] = Util.GetValueOfString(order.Get_ID());
            //retDic["DateOrdered"] = Convert.ToDateTime(order.GetDateOrdered()).ToLocalTime().ToUniversalTime();
            retDic["DateOrdered"]     = DateTime.SpecifyKind(order.GetDateOrdered().Value, DateTimeKind.Utc);
            retDic["DateAcct"]        = Util.GetValueOfString(order.GetDateAcct());
            retDic["POReference"]     = order.GetPOReference();
            retDic["AD_Org_ID"]       = Util.GetValueOfString(order.GetAD_Org_ID());
            retDic["DeliveryRule"]    = order.GetDeliveryRule();
            retDic["DeliveryViaRule"] = order.GetDeliveryViaRule();
            retDic["M_Shipper_ID"]    = Util.GetValueOfString(order.GetM_Shipper_ID());
            retDic["FreightAmt"]      = Util.GetValueOfString(order.GetFreightAmt());
            retDic["AD_OrgTrx_ID"]    = Util.GetValueOfString(order.GetAD_OrgTrx_ID());
            retDic["C_Activity_ID"]   = Util.GetValueOfString(order.GetC_Activity_ID());
            retDic["C_Campaign_ID"]   = Util.GetValueOfString(order.GetC_Campaign_ID());
            retDic["C_Project_ID"]    = Util.GetValueOfString(order.GetC_Project_ID());
            retDic["User1_ID"]        = Util.GetValueOfString(order.GetUser1_ID());
            retDic["User2_ID"]        = Util.GetValueOfString(order.GetUser2_ID());
            retDic["M_Warehouse_ID"]  = Util.GetValueOfString(order.GetM_Warehouse_ID());
            retDic["Orig_Order_ID"]   = Util.GetValueOfString(order.GetOrig_Order_ID());
            retDic["Orig_InOut_ID"]   = Util.GetValueOfString(order.GetOrig_InOut_ID());
            //Added By Amit
            retDic["IsSOTrx"]                = Util.GetValueOfString(order.IsSOTrx());
            retDic["IsReturnTrx"]            = Util.GetValueOfString(order.IsReturnTrx());
            retDic["C_Payment_ID"]           = Util.GetValueOfString(order.GetPaymentMethod());
            retDic["VA009_PaymentMethod_ID"] = Util.GetValueOfString(order.GetVA009_PaymentMethod_ID());
            retDic["SalesRep_ID"]            = Util.GetValueOfString(order.GetSalesRep_ID());
            retDic["C_ProjectRef_ID"]        = Util.GetValueOfString(order.GetC_ProjectRef_ID());
            retDic["PriorityRule"]           = Util.GetValueOfString(order.GetPriorityRule());


            if (order.GetC_Currency_ID() != 0)
            {
                retDic["C_Currency_ID"] = Util.GetValueOfString(order.GetC_Currency_ID());
            }
            else
            {
                retDic["C_Currency_ID"] = "0";
            }
            //End
            // added by vivek on 09/10/2017 advised by pradeep to set drop ship checkbox value
            retDic["IsDropShip"] = Util.GetValueOfBool(order.IsDropShip()) ? "Y" : "N";

            // Added by Bharat on 30 Jan 2018 to set Inco Term from Order

            if (order.Get_ColumnIndex("C_IncoTerm_ID") > 0)
            {
                retDic["C_IncoTerm_ID"] = Util.GetValueOfString(order.GetC_IncoTerm_ID());
            }

            if (Env.IsModuleInstalled("VA077_"))
            {
                retDic["VA077_HistoricContractDate"]   = Util.GetValueOfString(order.Get_Value("VA077_HistoricContractDate"));
                retDic["VA077_ChangeStartDate"]        = Util.GetValueOfString(order.Get_Value("VA077_ChangeStartDate"));
                retDic["VA077_ContractCPStartDate"]    = Util.GetValueOfString(order.Get_Value("VA077_ContractCPStartDate"));
                retDic["VA077_ContractCPEndDate"]      = Util.GetValueOfString(order.Get_Value("VA077_ContractCPEndDate"));
                retDic["VA077_PartialAmtCatchUp"]      = Util.GetValueOfString(order.Get_Value("VA077_PartialAmtCatchUp"));
                retDic["VA077_OldAnnualContractTotal"] = Util.GetValueOfString(order.Get_Value("VA077_OldAnnualContractTotal"));
                retDic["VA077_AdditionalAnnualCharge"] = Util.GetValueOfString(order.Get_Value("VA077_AdditionalAnnualCharge"));
                retDic["VA077_NewAnnualContractTotal"] = Util.GetValueOfString(order.Get_Value("VA077_NewAnnualContractTotal"));
                retDic["VA077_SalesCoWorker"]          = Util.GetValueOfString(order.Get_Value("VA077_SalesCoWorker"));
                retDic["VA077_SalesCoWorkerPer"]       = Util.GetValueOfString(order.Get_Value("VA077_SalesCoWorkerPer"));
                retDic["VA077_TotalMarginAmt"]         = Util.GetValueOfString(order.Get_Value("VA077_TotalMarginAmt"));
                retDic["VA077_TotalPurchaseAmt"]       = Util.GetValueOfString(order.Get_Value("VA077_TotalPurchaseAmt"));
                retDic["VA077_TotalSalesAmt"]          = Util.GetValueOfString(order.Get_Value("VA077_TotalSalesAmt"));
                retDic["VA077_MarginPercent"]          = Util.GetValueOfString(order.Get_Value("VA077_MarginPercent"));
            }

            return(retDic);
        }
Ejemplo n.º 3
0
        /**
         *  Generate Shipments
         *  @param pstmt order query
         *	@return info
         */
        private String Generate(IDataReader idr)
        {
            DataTable dt = new DataTable();

            try
            {
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)//  while (dr.next ())
                {
                    MOrder order = new MOrder(GetCtx(), dr, Get_TrxName());

                    //	New Invoice Location
                    if (!_ConsolidateDocument ||
                        (_invoice != null &&
                         (_invoice.GetC_BPartner_Location_ID() != order.GetBill_Location_ID() ||
                          _invoice.GetC_PaymentTerm_ID() != order.GetC_PaymentTerm_ID())))
                    {
                        CompleteInvoice();
                    }
                    bool completeOrder = MOrder.INVOICERULE_AfterOrderDelivered.Equals(order.GetInvoiceRule());

                    //	Schedule After Delivery
                    bool doInvoice = false;
                    if (MOrder.INVOICERULE_CustomerScheduleAfterDelivery.Equals(order.GetInvoiceRule()))
                    {
                        _bp = new MBPartner(GetCtx(), order.GetBill_BPartner_ID(), null);
                        if (_bp.GetC_InvoiceSchedule_ID() == 0)
                        {
                            log.Warning("BPartner has no Schedule - set to After Delivery");
                            order.SetInvoiceRule(MOrder.INVOICERULE_AfterDelivery);
                            order.Save();
                        }
                        else
                        {
                            MInvoiceSchedule ins = MInvoiceSchedule.Get(GetCtx(), _bp.GetC_InvoiceSchedule_ID(), Get_TrxName());
                            if (ins.CanInvoice(order.GetDateOrdered(), order.GetGrandTotal()))
                            {
                                doInvoice = true;
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }   //	Schedule

                    //	After Delivery
                    if (doInvoice || MOrder.INVOICERULE_AfterDelivery.Equals(order.GetInvoiceRule()))
                    {
                        MInOut       shipment      = null;
                        MInOutLine[] shipmentLines = order.GetShipmentLines();
                        for (int i = 0; i < shipmentLines.Length; i++)
                        {
                            MInOutLine shipLine = shipmentLines[i];
                            if (shipLine.IsInvoiced())
                            {
                                continue;
                            }
                            if (shipment == null ||
                                shipment.GetM_InOut_ID() != shipLine.GetM_InOut_ID())
                            {
                                shipment = new MInOut(GetCtx(), shipLine.GetM_InOut_ID(), Get_TrxName());
                            }
                            if (!shipment.IsComplete() ||       //	ignore incomplete or reversals
                                shipment.GetDocStatus().Equals(MInOut.DOCSTATUS_Reversed))
                            {
                                continue;
                            }
                            //
                            CreateLine(order, shipment, shipLine);
                        }       //	shipment lines
                        _line += 1000;
                    }
                    //	After Order Delivered, Immediate
                    else
                    {
                        MOrderLine[] oLines = order.GetLines(true, null);
                        for (int i = 0; i < oLines.Length; i++)
                        {
                            MOrderLine oLine     = oLines[i];
                            Decimal    toInvoice = Decimal.Subtract(oLine.GetQtyOrdered(), oLine.GetQtyInvoiced());
                            if (toInvoice.CompareTo(Env.ZERO) == 0 && oLine.GetM_Product_ID() != 0)
                            {
                                continue;
                            }
                            //
                            bool fullyDelivered = oLine.GetQtyOrdered().CompareTo(oLine.GetQtyDelivered()) == 0;

                            //	Complete Order
                            if (completeOrder && !fullyDelivered)
                            {
                                log.Fine("Failed CompleteOrder - " + oLine);
                                completeOrder = false;
                                break;
                            }
                            //	Immediate
                            else if (MOrder.INVOICERULE_Immediate.Equals(order.GetInvoiceRule()))
                            {
                                log.Fine("Immediate - ToInvoice=" + toInvoice + " - " + oLine);
                                Decimal qtyEntered = toInvoice;
                                //	Correct UOM for QtyEntered
                                if (oLine.GetQtyEntered().CompareTo(oLine.GetQtyOrdered()) != 0)
                                {
                                    qtyEntered = Decimal.Round(Decimal.Divide(Decimal.Multiply(
                                                                                  toInvoice, oLine.GetQtyEntered()),
                                                                              oLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero);
                                }
                                //
                                if (oLine.IsContract() == false)
                                {
                                    CreateLine(order, oLine, toInvoice, qtyEntered);
                                    log.Info("ID " + oLine.Get_ID() + "Qty Ordered " + oLine.GetQtyOrdered() + " Qty Invoiced " + oLine.GetQtyInvoiced());
                                }
                            }
                            else
                            {
                                log.Fine("Failed: " + order.GetInvoiceRule()
                                         + " - ToInvoice=" + toInvoice + " - " + oLine);
                            }
                        }       //	for all order lines
                        if (MOrder.INVOICERULE_Immediate.Equals(order.GetInvoiceRule()))
                        {
                            _line += 1000;
                        }
                    }

                    //	Complete Order successful
                    if (completeOrder && MOrder.INVOICERULE_AfterOrderDelivered.Equals(order.GetInvoiceRule()))
                    {
                        MInOut[] shipments = order.GetShipments(true);
                        for (int i = 0; i < shipments.Length; i++)
                        {
                            MInOut ship = shipments[i];
                            if (!ship.IsComplete() ||           //	ignore incomplete or reversals
                                ship.GetDocStatus().Equals(MInOut.DOCSTATUS_Reversed))
                            {
                                continue;
                            }
                            MInOutLine[] shipLines = ship.GetLines(false);
                            for (int j = 0; j < shipLines.Length; j++)
                            {
                                MInOutLine shipLine = shipLines[j];
                                if (!order.IsOrderLine(shipLine.GetC_OrderLine_ID()))
                                {
                                    continue;
                                }
                                if (!shipLine.IsInvoiced())
                                {
                                    CreateLine(order, ship, shipLine);
                                }
                            } //	lines
                            _line += 1000;
                        }     //	all shipments
                    }         //	complete Order
                }             //	for all orders
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                log.Log(Level.SEVERE, "", e);
            }
            finally
            {
                if (idr != null)
                {
                    idr.Close();
                }

                dt = null;
            }

            CompleteInvoice();
            return("@Created@ = " + _created);
        }
Ejemplo n.º 4
0
        public JsonResult GetOrder(string param)
        {
            string retError = "";
            string retJSON  = "";

            if (Session["ctx"] != null)
            {
                VAdvantage.Utility.Ctx ctx = Session["ctx"] as Ctx;
                string[] paramValue        = param.Split(',');
                int      C_Order_ID;

                //Assign parameter value
                C_Order_ID = Util.GetValueOfInt(paramValue[0].ToString());
                MOrder order = new MOrder(ctx, C_Order_ID, null);


                Dictionary <String, String> retDic = new Dictionary <string, string>();
                // Reset Orig Shipment



                retDic["C_BParter_ID"]           = order.GetC_BPartner_ID().ToString();
                retDic["C_BPartner_Location_ID"] = order.GetC_BPartner_Location_ID().ToString();
                retDic["Bill_BPartner_ID"]       = order.GetBill_BPartner_ID().ToString();
                retDic["Bill_Location_ID"]       = order.GetBill_Location_ID().ToString();

                if (order.GetAD_User_ID() != 0)
                {
                    retDic["AD_User_ID"] = order.GetAD_User_ID().ToString();
                }

                if (order.GetBill_User_ID() != 0)
                {
                    retDic["Bill_User_ID"] = order.GetBill_User_ID().ToString();
                }

                //if (ctx.IsSOTrx(WindowNo))
                //  retDic["M_ReturnPolicy_ID"]= bpartner.getM_ReturnPolicy_ID();
                //else
                //   retDic["M_ReturnPolicy_ID"]= bpartner.getPO_ReturnPolicy_ID();

                //retDic["DateOrdered", order.GetDateOrdered());
                retDic["M_PriceList_ID"]   = order.GetM_PriceList_ID().ToString();
                retDic["PaymentRule"]      = order.GetPaymentRule();
                retDic["C_PaymentTerm_ID"] = order.GetC_PaymentTerm_ID().ToString();
                //mTab.setValue ("DeliveryRule", X_C_Order.DELIVERYRULE_Manual);

                retDic["Bill_Location_ID"] = order.GetBill_Location_ID().ToString();
                retDic["InvoiceRule"]      = order.GetInvoiceRule();
                retDic["PaymentRule"]      = order.GetPaymentRule();
                retDic["DeliveryViaRule"]  = order.GetDeliveryViaRule();
                retDic["FreightCostRule"]  = order.GetFreightCostRule();
                //retlst.Add(retValue);

                //retVal.Add(notReserved);


                retJSON = JsonConvert.SerializeObject(retDic);
            }
            else
            {
                retError = "Session Expired";
            }
            return(Json(new { result = retJSON, error = retError }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Generate Invoices
        /// </summary>
        /// <param name="idr">pstmt order query</param>
        /// <returns>info</returns>
        //private String Generate(IDataReader idr)
        private String Generate(DataTable dt)
        {
            //JID_1139 Avoided the duplicate charge line created Invoice(customer)
            bool isAllownonItem = Util.GetValueOfString(GetCtx().GetContext("$AllowNonItem")).Equals("Y");

            foreach (DataRow dr in dt.Rows)
            {
                MOrder order = new MOrder(GetCtx(), dr, Get_TrxName());

                // Credit Limit check
                MBPartner bp = MBPartner.Get(GetCtx(), order.GetC_BPartner_ID());
                if (bp.GetCreditStatusSettingOn() == "CH")
                {
                    decimal creditLimit = bp.GetSO_CreditLimit();
                    string  creditVal   = bp.GetCreditValidation();
                    if (creditLimit != 0)
                    {
                        decimal creditAvlb = creditLimit - bp.GetSO_CreditUsed();
                        if (creditAvlb <= 0)
                        {
                            if (creditVal == "C" || creditVal == "D" || creditVal == "F")
                            {
                                AddLog(Msg.GetMsg(GetCtx(), "StopInvoice") + bp.GetName());
                                continue;
                            }
                            else if (creditVal == "I" || creditVal == "J" || creditVal == "L")
                            {
                                if (_msg != null)
                                {
                                    _msg.Clear();
                                }
                                _msg.Append(Msg.GetMsg(GetCtx(), "WarningInvoice") + bp.GetName());
                                //AddLog(Msg.GetMsg(GetCtx(), "WarningInvoice") + bp.GetName());
                            }
                        }
                    }
                }
                // JID_0161 // change here now will check credit settings on field only on Business Partner Header // Lokesh Chauhan 15 July 2019
                else if (bp.GetCreditStatusSettingOn() == X_C_BPartner.CREDITSTATUSSETTINGON_CustomerLocation)
                {
                    MBPartnerLocation bpl = new MBPartnerLocation(GetCtx(), order.GetC_BPartner_Location_ID(), null);
                    //MBPartner bpartner = MBPartner.Get(GetCtx(), order.GetC_BPartner_ID());
                    //if (bpl.GetCreditStatusSettingOn() == "CL")
                    //{
                    decimal creditLimit = bpl.GetSO_CreditLimit();
                    string  creditVal   = bpl.GetCreditValidation();
                    if (creditLimit != 0)
                    {
                        decimal creditAvlb = creditLimit - bpl.GetSO_CreditUsed();
                        if (creditAvlb <= 0)
                        {
                            if (creditVal == "C" || creditVal == "D" || creditVal == "F")
                            {
                                AddLog(Msg.GetMsg(GetCtx(), "StopInvoice") + bp.GetName() + " " + bpl.GetName());
                                continue;
                            }
                            else if (creditVal == "I" || creditVal == "J" || creditVal == "L")
                            {
                                if (_msg != null)
                                {
                                    _msg.Clear();
                                }
                                _msg.Append(Msg.GetMsg(GetCtx(), "WarningInvoice") + bp.GetName() + " " + bpl.GetName());
                                //AddLog(Msg.GetMsg(GetCtx(), "WarningInvoice") + bp.GetName() + " " + bpl.GetName());
                            }
                        }
                    }
                    //}
                }
                // Credit Limit End

                //	New Invoice Location
                // JID_1237 : While creating invoice need to consolidate order on the basis of Org, Payment Term, BP Location (Bill to Location) and Pricelist.
                if (!_ConsolidateDocument ||
                    (_invoice != null &&
                     (_invoice.GetC_BPartner_Location_ID() != order.GetBill_Location_ID() ||
                      _invoice.GetC_PaymentTerm_ID() != order.GetC_PaymentTerm_ID() ||
                      _invoice.GetM_PriceList_ID() != order.GetM_PriceList_ID() ||
                      _invoice.GetAD_Org_ID() != order.GetAD_Org_ID() ||
                      ((_invoice.GetC_ConversionType_ID() != 0 ? _invoice.GetC_ConversionType_ID() : defaultConversionType)
                       != (order.GetC_ConversionType_ID() != 0 ? order.GetC_ConversionType_ID() : defaultConversionType))
                     )))
                {
                    CompleteInvoice();
                }
                bool completeOrder = MOrder.INVOICERULE_AfterOrderDelivered.Equals(order.GetInvoiceRule());

                //	Schedule After Delivery
                bool doInvoice = false;
                if (MOrder.INVOICERULE_CustomerScheduleAfterDelivery.Equals(order.GetInvoiceRule()))
                {
                    _bp = new MBPartner(GetCtx(), order.GetBill_BPartner_ID(), null);
                    if (_bp.GetC_InvoiceSchedule_ID() == 0)
                    {
                        log.Warning("BPartner has no Schedule - set to After Delivery");
                        order.SetInvoiceRule(MOrder.INVOICERULE_AfterDelivery);
                        order.Save();
                    }
                    else
                    {
                        MInvoiceSchedule ins = MInvoiceSchedule.Get(GetCtx(), _bp.GetC_InvoiceSchedule_ID(), Get_TrxName());
                        if (ins.CanInvoice(order.GetDateOrdered(), order.GetGrandTotal()))
                        {
                            doInvoice = true;
                        }
                        else
                        {
                            continue;
                        }
                    }
                }       //	Schedule

                //	After Delivery
                if (doInvoice || MOrder.INVOICERULE_AfterDelivery.Equals(order.GetInvoiceRule()))
                {
                    MInOut       shipment      = null;
                    MInOutLine[] shipmentLines = order.GetShipmentLines();
                    MOrderLine[] oLines        = order.GetLines(true, null);
                    for (int i = 0; i < shipmentLines.Length; i++)
                    {
                        MInOutLine shipLine = shipmentLines[i];
                        if (shipLine.IsInvoiced())
                        {
                            continue;
                        }
                        if (shipment == null ||
                            shipment.GetM_InOut_ID() != shipLine.GetM_InOut_ID())
                        {
                            shipment = new MInOut(GetCtx(), shipLine.GetM_InOut_ID(), Get_TrxName());
                        }
                        if (!shipment.IsComplete() ||           //	ignore incomplete or reversals
                            shipment.GetDocStatus().Equals(MInOut.DOCSTATUS_Reversed))
                        {
                            continue;
                        }
                        //JID_1139 Avoided the duplicate charge records
                        if (shipLine.GetM_Product_ID() > 0 || isAllownonItem)
                        {
                            CreateLine(order, shipment, shipLine);
                        }
                    }//	shipment lines

                    //JID_1139 Avoided the duplicate charge records
                    if (!isAllownonItem)
                    {
                        for (int i = 0; i < oLines.Length; i++)
                        {
                            MOrderLine oLine = oLines[i];
                            if (oLine.GetC_Charge_ID() > 0)
                            {
                                Decimal toInvoice = Decimal.Subtract(oLine.GetQtyOrdered(), oLine.GetQtyInvoiced());
                                log.Fine("Immediate - ToInvoice=" + toInvoice + " - " + oLine);
                                Decimal qtyEntered = toInvoice;
                                //	Correct UOM for QtyEntered
                                if (oLine.GetQtyEntered().CompareTo(oLine.GetQtyOrdered()) != 0)
                                {
                                    qtyEntered = Decimal.Round(Decimal.Divide(Decimal.Multiply(
                                                                                  toInvoice, oLine.GetQtyEntered()),
                                                                              oLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero);
                                }
                                //JID_1139_1 avoided the charge line with 0 qty inserted
                                if (oLine.IsContract() == false && oLine.GetQtyOrdered() > oLine.GetQtyInvoiced())
                                {
                                    CreateLine(order, oLine, toInvoice, qtyEntered);
                                    log.Info("ID " + oLine.Get_ID() + "Qty Ordered " + oLine.GetQtyOrdered() + " Qty Invoiced " + oLine.GetQtyInvoiced());
                                }
                            }
                        }
                    }
                }
                //	After Order Delivered, Immediate
                else
                {
                    MOrderLine[] oLines = order.GetLines(true, null);
                    for (int i = 0; i < oLines.Length; i++)
                    {
                        MOrderLine oLine     = oLines[i];
                        Decimal    toInvoice = Decimal.Subtract(oLine.GetQtyOrdered(), oLine.GetQtyInvoiced());
                        if (toInvoice.CompareTo(Env.ZERO) == 0 && oLine.GetM_Product_ID() != 0)
                        {
                            continue;
                        }
                        //
                        bool fullyDelivered = oLine.GetQtyOrdered().CompareTo(oLine.GetQtyDelivered()) == 0;
                        //JID_1136: While creating the Invoices against the charge system should not check the Ordered qty= Delivered qty. need to check this only in case of products
                        if (completeOrder && oLine.GetC_Charge_ID() > 0)
                        {
                            fullyDelivered = true;
                            if (oLine.GetC_Charge_ID() > 0)
                            {
                                log.Fine("After Order Delivery - ToInvoice=" + toInvoice + " - " + oLine);
                                Decimal qtyEntered = toInvoice;
                                //	Correct UOM for QtyEntered
                                if (oLine.GetQtyEntered().CompareTo(oLine.GetQtyOrdered()) != 0)
                                {
                                    qtyEntered = Decimal.Round(Decimal.Divide(Decimal.Multiply(
                                                                                  toInvoice, oLine.GetQtyEntered()),
                                                                              oLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero);
                                }
                                //
                                if (oLine.IsContract() == false && !isAllownonItem)
                                {
                                    CreateLine(order, oLine, toInvoice, qtyEntered);
                                    log.Info("ID " + oLine.Get_ID() + "Qty Ordered " + oLine.GetQtyOrdered() + " Qty Invoiced " + oLine.GetQtyInvoiced());
                                }
                            }
                        }

                        //	Complete Order
                        if (completeOrder && !fullyDelivered)
                        {
                            log.Fine("Failed CompleteOrder - " + oLine);
                            completeOrder = false;
                            break;
                        }
                        //	Immediate
                        else if (MOrder.INVOICERULE_Immediate.Equals(order.GetInvoiceRule()))
                        {
                            log.Fine("Immediate - ToInvoice=" + toInvoice + " - " + oLine);
                            Decimal qtyEntered = toInvoice;
                            //	Correct UOM for QtyEntered
                            if (oLine.GetQtyEntered().CompareTo(oLine.GetQtyOrdered()) != 0)
                            {
                                qtyEntered = Decimal.Round(Decimal.Divide(Decimal.Multiply(
                                                                              toInvoice, oLine.GetQtyEntered()),
                                                                          oLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero);
                            }
                            //
                            if (oLine.IsContract() == false)
                            {
                                CreateLine(order, oLine, toInvoice, qtyEntered);
                                log.Info("ID " + oLine.Get_ID() + "Qty Ordered " + oLine.GetQtyOrdered() + " Qty Invoiced " + oLine.GetQtyInvoiced());
                            }
                        }
                        else
                        {
                            log.Fine("Failed: " + order.GetInvoiceRule()
                                     + " - ToInvoice=" + toInvoice + " - " + oLine);
                        }
                    }   //	for all order lines
                    if (MOrder.INVOICERULE_Immediate.Equals(order.GetInvoiceRule()))
                    {
                        _line += 1000;
                    }
                }

                //	Complete Order successful
                if (completeOrder && MOrder.INVOICERULE_AfterOrderDelivered.Equals(order.GetInvoiceRule()))
                {
                    MInOut[] shipments = order.GetShipments(true);
                    for (int i = 0; i < shipments.Length; i++)
                    {
                        MInOut ship = shipments[i];
                        if (!ship.IsComplete() ||       //	ignore incomplete or reversals
                            ship.GetDocStatus().Equals(MInOut.DOCSTATUS_Reversed))
                        {
                            continue;
                        }
                        MInOutLine[] shipLines = ship.GetLines(false);
                        for (int j = 0; j < shipLines.Length; j++)
                        {
                            MInOutLine shipLine = shipLines[j];
                            if (!order.IsOrderLine(shipLine.GetC_OrderLine_ID()))
                            {
                                continue;
                            }
                            if (!shipLine.IsInvoiced())
                            {
                                CreateLine(order, ship, shipLine);
                            }
                        } //	lines
                        _line += 1000;
                    }     //	all shipments
                }         //	complete Order
            }             //	for all orders

            CompleteInvoice();
            return("@Created@ = " + _created);
        }