/// <summary> /// After Save /// </summary> /// <param name="newRecord">new record</param> /// <param name="success">success</param> /// <returns>success</returns> protected override bool AfterSave(bool newRecord, bool success) { // Purchase Order Delivered/Invoiced // (Reserved in VMatch and MInOut.completeIt) if (success && GetC_OrderLine_ID() != 0) { MOrderLine orderLine = GetOrderLine(); bool isReturnTrx = orderLine.GetParent().IsReturnTrx(); // if (_isInOutLineChange) { if (GetM_InOutLine_ID() != 0) // new delivery { orderLine.SetQtyDelivered(Decimal.Add(orderLine.GetQtyDelivered(), GetQty())); if (isReturnTrx) { orderLine.SetQtyReturned(Decimal.Add(orderLine.GetQtyReturned(), GetQty())); MOrderLine origOrderLine = new MOrderLine(GetCtx(), orderLine.GetOrig_OrderLine_ID(), Get_Trx()); origOrderLine.SetQtyReturned(Decimal.Add(origOrderLine.GetQtyReturned(), GetQty())); origOrderLine.Save(); } } else // if (getM_InOutLine_ID() == 0) // reset to 0 { orderLine.SetQtyDelivered(Decimal.Subtract(orderLine.GetQtyDelivered(), GetQty())); if (isReturnTrx) { orderLine.SetQtyReturned(Decimal.Subtract(orderLine.GetQtyReturned(), GetQty())); MOrderLine origOrderLine = new MOrderLine(GetCtx(), orderLine.GetOrig_OrderLine_ID(), Get_Trx()); origOrderLine.SetQtyReturned(Decimal.Add(origOrderLine.GetQtyReturned(), GetQty())); origOrderLine.Save(); } } orderLine.SetDateDelivered(GetDateTrx()); // overwrite=last } if (_isInvoiceLineChange) { if (GetC_InvoiceLine_ID() != 0) // first time { orderLine.SetQtyInvoiced(Decimal.Add(orderLine.GetQtyInvoiced(), GetQty())); } else // if (getC_InvoiceLine_ID() == 0) // set to 0 { orderLine.SetQtyInvoiced(Decimal.Subtract(orderLine.GetQtyInvoiced(), GetQty())); } orderLine.SetDateInvoiced(GetDateTrx()); // overwrite=last } // Update Order ASI if full match //if (orderLine.GetM_AttributeSetInstance_ID() == 0 // && GetM_InOutLine_ID() != 0) //{ // MInOutLine iol = new MInOutLine(GetCtx(), GetM_InOutLine_ID(), Get_Trx()); // if (iol.GetMovementQty().CompareTo(orderLine.GetQtyOrdered()) == 0) // orderLine.SetM_AttributeSetInstance_ID(iol.GetM_AttributeSetInstance_ID()); //} orderLine.Save(); } return(success); }
/* Set Order Line - Callout * @param oldC_OrderLine_ID old BP * @param newC_OrderLine_ID new BP * @param windowNo window no */ //@UICallout public void SetC_OrderLine_ID(String oldC_OrderLine_ID, String newC_OrderLine_ID, int windowNo) { if (newC_OrderLine_ID == null || newC_OrderLine_ID.Length == 0) { return; } int C_OrderLine_ID = int.Parse(newC_OrderLine_ID); if (C_OrderLine_ID == 0) { return; } MOrderLine ol = new MOrderLine(GetCtx(), C_OrderLine_ID, null); if (ol.Get_ID() != 0) { SetC_OrderLine_ID(C_OrderLine_ID); Decimal MovementQty = Decimal.Subtract(ol.GetQtyOrdered(), ol.GetQtyDelivered()); SetMovementQty(MovementQty); SetOrderLine(ol, 0, MovementQty); Decimal QtyEntered = MovementQty; if (ol.GetQtyEntered().CompareTo(ol.GetQtyOrdered()) != 0) { //QtyEntered = QtyEntered.multiply(ol.getQtyEntered()).divide(ol.getQtyOrdered(), 12, Decimal.ROUND_HALF_UP); QtyEntered = Decimal.Divide((Decimal.Multiply(QtyEntered, ol.GetQtyEntered())), ol.GetQtyOrdered()); } SetQtyEntered(QtyEntered); if (ol.GetParent().IsReturnTrx()) { MInOutLine ioLine = new MInOutLine(GetCtx(), ol.GetOrig_InOutLine_ID(), null); SetM_Locator_ID(ioLine.GetM_Locator_ID()); } } }
/// <summary> /// After Delete. /// Set Order Qty Delivered/Invoiced /// </summary> /// <param name="success">success</param> /// <returns>success</returns> protected override bool AfterDelete(bool success) { // Order Delivered/Invoiced // (Reserved in VMatch and MInOut.completeIt) if (success && GetC_OrderLine_ID() != 0) { MOrderLine orderLine = new MOrderLine(GetCtx(), GetC_OrderLine_ID(), Get_Trx()); Boolean IsReturnTrx = orderLine.GetParent().IsReturnTrx(); if (GetM_InOutLine_ID() != 0) { orderLine.SetQtyDelivered(Decimal.Subtract(orderLine.GetQtyDelivered(), GetQty())); if (IsReturnTrx) { orderLine.SetQtyReturned(Decimal.Subtract(orderLine.GetQtyReturned(), GetQty())); MOrderLine origOrderLine = new MOrderLine(GetCtx(), orderLine.GetOrig_OrderLine_ID(), Get_Trx()); origOrderLine.SetQtyReturned(Decimal.Subtract(origOrderLine.GetQtyReturned(), GetQty())); origOrderLine.Save(); } } if (GetC_InvoiceLine_ID() != 0) { orderLine.SetQtyInvoiced(Decimal.Subtract(orderLine.GetQtyInvoiced(), GetQty())); } return(orderLine.Save(Get_Trx())); } return(success); }
/************************************************************************** * Create Invoice Line from Order Line * @param order order * @param orderLine line * @param qtyInvoiced qty * @param qtyEntered qty */ private void CreateLine(MOrder order, MOrderLine orderLine, Decimal qtyInvoiced, Decimal qtyEntered) { if (_invoice == null) { _invoice = new MInvoice(order, 0, _DateInvoiced); if (!_invoice.Save()) { throw new Exception("Could not create Invoice (o)"); } } // MInvoiceLine line = new MInvoiceLine(_invoice); line.SetOrderLine(orderLine); line.SetQtyInvoiced(qtyInvoiced); log.Info("Qty Invoiced" + line.GetQtyInvoiced()); line.SetQtyEntered(qtyEntered); line.SetLine(_line + orderLine.GetLine()); if (!line.Save()) { throw new Exception("Could not create Invoice Line (o)"); } log.Fine(line.ToString()); }
/// <summary> /// Get Order Line /// </summary> /// <returns>order line or null</returns> public MOrderLine GetOrderLine() { if ((_oLine == null && GetC_OrderLine_ID() != 0) || GetC_OrderLine_ID() != _oLine.GetC_OrderLine_ID()) { _oLine = new MOrderLine(GetCtx(), GetC_OrderLine_ID(), Get_Trx()); } return(_oLine); }
/// <summary> /// Get Not Reserved /// </summary> /// <param name="ctx"></param> /// <param name="fields"></param> /// <returns></returns> public Decimal GetNotReserved(Ctx ctx, string fields) { string[] paramValue = fields.Split(','); //Assign parameter value int M_Warehouse_ID = Util.GetValueOfInt(paramValue[0].ToString()); int M_Product_ID = Util.GetValueOfInt(paramValue[1].ToString()); int M_AttributeSetInstance_ID = Util.GetValueOfInt(paramValue[2].ToString()); int C_OrderLine_ID = Util.GetValueOfInt(paramValue[3].ToString()); //End Assign parameter value return(MOrderLine.GetNotReserved(ctx, M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID, C_OrderLine_ID)); }
/// <summary> /// Set C_OrderLine_ID /// </summary> /// <param name="line">line</param> public void SetC_OrderLine_ID(MOrderLine line) { _oLine = line; if (line == null) { SetC_OrderLine_ID(0); } else { SetC_OrderLine_ID(line.GetC_OrderLine_ID()); } }
/************************************************************************** * Create Invoice Line from Order Line * @param order order * @param orderLine line * @param qtyInvoiced qty * @param qtyEntered qty */ private void CreateLine(MOrder order, MOrderLine orderLine, Decimal qtyInvoiced, Decimal qtyEntered) { if (_invoice == null) { _invoice = new MInvoice(order, 0, _DateInvoiced); //-----------------Column Added by Anuj------------------ int _CountVA009 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA009_' AND IsActive = 'Y'")); if (_CountVA009 > 0) { int _PaymentMethod_ID = order.GetVA009_PaymentMethod_ID(); if (_PaymentMethod_ID > 0) { _invoice.SetVA009_PaymentMethod_ID(_PaymentMethod_ID); } } //-----------------Column Added by Anuj------------------ int _CountVA026 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA026_' AND IsActive = 'Y'")); if (_CountVA026 > 0) { _invoice.SetVA026_LCDetail_ID(order.GetVA026_LCDetail_ID()); } // Added by Bharat on 29 Jan 2018 to set Inco Term from Order if (_invoice.Get_ColumnIndex("C_IncoTerm_ID") > 0) { _invoice.SetC_IncoTerm_ID(order.GetC_IncoTerm_ID()); } if (!_invoice.Save()) { throw new Exception("Could not create Invoice (o)"); } } // MInvoiceLine line = new MInvoiceLine(_invoice); line.SetOrderLine(orderLine); line.SetQtyInvoiced(qtyInvoiced); // if drop ship line true line.SetIsDropShip(orderLine.IsDropShip()); log.Info("Qty Invoiced" + line.GetQtyInvoiced()); line.SetQtyEntered(qtyEntered); line.SetLine(_line + orderLine.GetLine()); if (!line.Save()) { throw new Exception("Could not create Invoice Line (o)"); } log.Fine(line.ToString()); }
/// <summary> /// Create PO's /// </summary> private void CreatePO() { int noOrders = 0; String info = ""; // MOrder order = null; MWarehouse wh = null; X_T_Replenish[] replenishs = GetReplenish(_M_WareSource); for (int i = 0; i < replenishs.Length; i++) { X_T_Replenish replenish = replenishs[i]; if (wh == null || wh.GetM_Warehouse_ID() != replenish.GetM_Warehouse_ID()) { wh = MWarehouse.Get(GetCtx(), replenish.GetM_Warehouse_ID()); } // if (order == null || order.GetC_BPartner_ID() != replenish.GetC_BPartner_ID() || order.GetM_Warehouse_ID() != replenish.GetM_Warehouse_ID()) { order = new MOrder(GetCtx(), 0, Get_TrxName()); order.SetIsSOTrx(false); order.SetC_DocTypeTarget_ID(_C_DocType_ID); MBPartner bp = new MBPartner(GetCtx(), replenish.GetC_BPartner_ID(), Get_TrxName()); order.SetBPartner(bp); order.SetSalesRep_ID(GetAD_User_ID()); order.SetDescription(Msg.GetMsg(GetCtx(), "Replenishment")); // Set Org/WH order.SetAD_Org_ID(wh.GetAD_Org_ID()); order.SetM_Warehouse_ID(wh.GetM_Warehouse_ID()); if (!order.Save()) { return; } log.Fine(order.ToString()); noOrders++; info += " - " + order.GetDocumentNo(); } MOrderLine line = new MOrderLine(order); line.SetM_Product_ID(replenish.GetM_Product_ID()); line.SetQty(replenish.GetQtyToOrder()); line.SetPrice(); line.Save(); } _info = "#" + noOrders + info; log.Info(_info); } // createPO
/** * Set Order Line. * Does not set Quantity! * @param oLine order line * @param M_Locator_ID locator * @param Qty used only to find suitable locator */ public void SetOrderLine(MOrderLine oLine, int M_Locator_ID, Decimal Qty) { SetC_OrderLine_ID(oLine.GetC_OrderLine_ID()); SetLine(oLine.GetLine()); SetC_UOM_ID(oLine.GetC_UOM_ID()); MProduct product = oLine.GetProduct(); if (product == null) { SetM_Product_ID(0); SetM_AttributeSetInstance_ID(0); base.SetM_Locator_ID(0); } else { SetM_Product_ID(oLine.GetM_Product_ID()); SetM_AttributeSetInstance_ID(oLine.GetM_AttributeSetInstance_ID()); // if (product.IsItem()) { if (M_Locator_ID == 0) { SetM_Locator_ID(Qty); // requires warehouse, product, asi } else { SetM_Locator_ID(M_Locator_ID); } } else { base.SetM_Locator_ID(0); } } SetC_Charge_ID(oLine.GetC_Charge_ID()); SetDescription(oLine.GetDescription()); SetIsDescription(oLine.IsDescription()); // SetC_Project_ID(oLine.GetC_Project_ID()); SetC_ProjectPhase_ID(oLine.GetC_ProjectPhase_ID()); SetC_ProjectTask_ID(oLine.GetC_ProjectTask_ID()); SetC_Activity_ID(oLine.GetC_Activity_ID()); SetC_Campaign_ID(oLine.GetC_Campaign_ID()); SetAD_OrgTrx_ID(oLine.GetAD_OrgTrx_ID()); SetUser1_ID(oLine.GetUser1_ID()); SetUser2_ID(oLine.GetUser2_ID()); }
/// <summary> /// GetOrderLine /// </summary> /// <param name="ctx"></param> /// <param name="param"></param> /// <returns></returns> public Dictionary <String, String> GetOrderLine(Ctx ctx, string param) { string[] paramValue = param.Split(','); Dictionary <String, String> retDic = new Dictionary <string, string>(); //Assign parameter value int id; id = Util.GetValueOfInt(paramValue[0].ToString()); //End Assign parameter value MOrderLine orderline = new MOrderLine(ctx, id, null); retDic["C_Tax_ID"] = Util.GetValueOfString(orderline.GetC_Tax_ID()); retDic["PriceList"] = Util.GetValueOfString(orderline.GetPriceList()); retDic["PriceLimit"] = Util.GetValueOfString(orderline.GetPriceLimit()); retDic["PriceActual"] = Util.GetValueOfString(orderline.GetPriceActual()); retDic["PriceEntered"] = Util.GetValueOfString(orderline.GetPriceEntered()); retDic["C_Currency_ID"] = Util.GetValueOfString(orderline.GetC_Currency_ID()); retDic["Discount"] = Util.GetValueOfString(orderline.GetDiscount()); retDic["Discount"] = Util.GetValueOfString(orderline.GetDiscount()); retDic["M_Product_ID"] = Util.GetValueOfString(orderline.GetM_Product_ID()); retDic["Qty"] = Util.GetValueOfString(orderline.GetQtyEntered()); retDic["C_UOM_ID"] = Util.GetValueOfString(orderline.GetC_UOM_ID()); retDic["C_BPartner_ID"] = Util.GetValueOfString(orderline.GetC_BPartner_ID()); retDic["PlannedHours"] = Util.GetValueOfString(orderline.GetQtyOrdered()); retDic["M_AttributeSetInstance_ID"] = Util.GetValueOfString(orderline.GetM_AttributeSetInstance_ID()); retDic["QtyOrdered"] = Util.GetValueOfString(orderline.GetQtyOrdered()); retDic["QtyDelivered"] = Util.GetValueOfString(orderline.GetQtyDelivered()); retDic["QtyEntered"] = Util.GetValueOfString(orderline.GetQtyEntered()); retDic["C_Activity_ID"] = Util.GetValueOfString(orderline.GetC_Activity_ID()); retDic["C_Campaign_ID"] = Util.GetValueOfString(orderline.GetC_Campaign_ID()); retDic["C_Project_ID"] = Util.GetValueOfString(orderline.GetC_Project_ID()); retDic["C_ProjectPhase_ID"] = Util.GetValueOfString(orderline.GetC_ProjectPhase_ID()); retDic["C_ProjectTask_ID"] = Util.GetValueOfString(orderline.GetC_ProjectTask_ID()); retDic["AD_OrgTrx_ID"] = Util.GetValueOfString(orderline.GetAD_OrgTrx_ID()); retDic["User1_ID"] = Util.GetValueOfString(orderline.GetUser1_ID()); retDic["User2_ID"] = Util.GetValueOfString(orderline.GetUser2_ID()); retDic["IsReturnTrx"] = Util.GetValueOfString(orderline.GetParent().IsReturnTrx()).ToLower(); retDic["Orig_InOutLine_ID"] = Util.GetValueOfString(orderline.GetOrig_InOutLine_ID()); retDic["Orig_OrderLine_ID"] = Util.GetValueOfString(orderline.GetOrig_OrderLine_ID()); retDic["GetID"] = Util.GetValueOfString(orderline.Get_ID()); return(retDic); }
/// <summary> ///Close Order /// </summary> private void CloseOrder() { if (_orderLine != null) { if (!_orderLine.Save()) { throw new Exception("Cannot update Order Line"); } } if (_order != null) { _order.Load(Get_TrxName()); AddLog(0, null, _order.GetGrandTotal(), _order.GetDocumentNo()); } _order = null; _orderLine = null; }
/// <summary> /// Save to Order /// </summary> /// <param name="C_Order_ID">id</param> /// <returns>true if saved</returns> private bool Cmd_SaveOrder(Ctx ctx, int C_Order_ID) { log.Config("C_Order_ID=" + C_Order_ID); MOrder order = new MOrder(ctx, C_Order_ID, null); if (order.Get_ID() == 0) { log.Log(Level.SEVERE, "Not found - C_Order_ID=" + C_Order_ID); } int lineCount = 0; bool chk = false; Decimal qty = 0; // for all bom lines if (_selectionList != null) { bool isQtySet = false; for (int i = 0; i < _selectionList.Count; i++) { if (_selectionList[i].IsSelected) { int M_Product_ID = Util.GetValueOfInt(_selectionList[i].ProductID);//.intValue(); // Create Line MOrderLine ol = new MOrderLine(order); ol.SetM_Product_ID(Util.GetValueOfInt(_selectionList[i].ProductID)); ol.SetQty(Util.GetValueOfInt(_selectionList[i].BOMQty)); ol.SetPrice(); ol.SetTax(); if (ol.Save()) { lineCount++; } else { log.Log(Level.SEVERE, "Line not saved"); } } // line selected } // for all bom lines } log.Config("#" + lineCount); return(true); }
public JsonResult GetQtyInfo(string fields) { string retError = ""; string retJSON = ""; if (Session["ctx"] != null) { VAdvantage.Utility.Ctx ctx = Session["ctx"] as Ctx; string[] paramValue = fields.Split(','); int M_Product_ID, M_Warehouse_ID, M_AttributeSetInstance_ID, C_OrderLine_ID; //Assign parameter value M_Product_ID = Util.GetValueOfInt(paramValue[0].ToString()); M_Warehouse_ID = Util.GetValueOfInt(paramValue[1].ToString()); M_AttributeSetInstance_ID = Util.GetValueOfInt(paramValue[2].ToString()); C_OrderLine_ID = Util.GetValueOfInt(paramValue[3].ToString()); //End Assign parameter value //var QtyOrdered = Utility.Util.getValueOfDecimal(mTab.getValue("QtyOrdered")); //var M_Warehouse_ID = ctx.getContextAsInt(WindowNo, "M_Warehouse_ID"); //var M_AttributeSetInstance_ID = ctx.getContextAsInt(WindowNo, "M_AttributeSetInstance_ID"); Decimal?available = MStorage.GetQtyAvailable(M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID, null); Decimal notReserved = MOrderLine.GetNotReserved(ctx, M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID, C_OrderLine_ID); List <Decimal?> retVal = new List <Decimal?>(); retVal.Add(available); retVal.Add(notReserved); retJSON = JsonConvert.SerializeObject(retVal); } else { retError = "Session Expired"; } return(Json(new { result = retJSON, error = retError }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Create Sales Quotation Lines /// </summary> /// <param name="ctx"></param> /// <param name="ReqLines">Related Product data</param> /// <param name="Record_ID">Record ID</param> /// <returns>Message as string</returns> public string CreateSQLines(Ctx ctx, List <RelatedProductData> ReqLines, int Record_ID) { int TotalCount, SavedCount = 0; int LineNo; string msg; MOrderLine POLine; LineNo = Util.GetValueOfInt(DB.ExecuteScalar("SELECT MAX(Line) FROM C_OrderLine WHERE C_Order_ID=" + Record_ID)); MOrder PO = new MOrder(ctx, Record_ID, null); TotalCount = ReqLines.Count; for (int i = 0; i < ReqLines.Count; i++) { LineNo += 10; POLine = new MOrderLine(PO); POLine.SetM_Product_ID(ReqLines[i].Product_ID); POLine.SetM_AttributeSetInstance_ID(ReqLines[i].AttributeSetInstance_ID); POLine.SetC_UOM_ID(ReqLines[i].UOM_ID); POLine.SetQtyEntered(ReqLines[i].QtyEntered); POLine.SetQtyOrdered(ReqLines[i].QtyEntered); POLine.SetDatePromised(PO.GetDatePromised()); POLine.SetLine(LineNo); POLine.SetDateOrdered(DateTime.Now); POLine.SetPriceEntered(ReqLines[i].PriceStd); POLine.SetPriceActual(ReqLines[i].PriceStd); POLine.SetPriceList(ReqLines[i].PriceList); if (POLine.Save()) { SavedCount++; } } if (TotalCount == SavedCount) { msg = Msg.GetMsg(ctx, "VIS_SuccessFullyInserted"); } else { msg = SavedCount + Msg.GetMsg(ctx, "VIS_NoOfLineSaved") + TotalCount + "."; } return(msg); }
/// <summary> /// Load Document Details /// </summary> /// <returns>error message or null</returns> public override String LoadDocumentDetails() { SetC_Currency_ID(Doc.NO_CURRENCY); MMatchPO matchPO = (MMatchPO)GetPO(); SetDateDoc(matchPO.GetDateTrx()); // _M_AttributeSetInstance_ID = matchPO.GetM_AttributeSetInstance_ID(); SetQty(matchPO.GetQty()); // _C_OrderLine_ID = matchPO.GetC_OrderLine_ID(); _oLine = new MOrderLine(GetCtx(), _C_OrderLine_ID, GetTrxName()); // _M_InOutLine_ID = matchPO.GetM_InOutLine_ID(); // m_C_InvoiceLine_ID = matchPO.getC_InvoiceLine_ID(); // _pc = new ProductCost(GetCtx(), GetM_Product_ID(), _M_AttributeSetInstance_ID, GetTrxName()); _pc.SetQty(GetQty()); return(null); }
public JsonResult GetOrderLine(string param) { string retError = ""; string retJSON = ""; if (Session["ctx"] != null) { VAdvantage.Utility.Ctx ctx = Session["ctx"] as Ctx; string[] paramValue = param.Split(','); Dictionary <String, String> retDic = new Dictionary <string, string>(); //Assign parameter value int id; id = Util.GetValueOfInt(paramValue[0].ToString()); MOrderLine orderline = new MOrderLine(ctx, id, null); //retDic["Orig_InOutLine_ID", null); retDic["C_Tax_ID"] = orderline.GetC_Tax_ID().ToString(); retDic["PriceList"] = orderline.GetPriceList().ToString(); retDic["PriceLimit"] = orderline.GetPriceLimit().ToString(); retDic["PriceActual"] = orderline.GetPriceActual().ToString(); retDic["PriceEntered"] = orderline.GetPriceEntered().ToString(); retDic["C_Currency_ID"] = orderline.GetC_Currency_ID().ToString(); retDic["Discount"] = orderline.GetDiscount().ToString(); retDic["Discount"] = orderline.GetDiscount().ToString(); //retlst.Add(retValue); //retVal.Add(notReserved); retJSON = JsonConvert.SerializeObject(retDic); } else { retError = "Session Expired"; } return(Json(new { result = retJSON, error = retError }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Get Order Lines having only product whihc is of Item type /// </summary> /// <param name="C_Order_ID">order id</param> /// <returns>order lines</returns> public MOrderLine[] GetLinesItemProduct(int C_Order_ID) { List <MOrderLine> list = new List <MOrderLine>(); StringBuilder sql = new StringBuilder(@"SELECT * FROM C_OrderLine ol INNER JOIN m_product p ON p.m_product_id = ol.m_product_id WHERE ol.C_Order_ID =" + C_Order_ID + @" AND ol.isactive = 'Y' AND p.ProductType = '" + MProduct.PRODUCTTYPE_Item + "'"); IDataReader idr = null; try { idr = DB.ExecuteReader(sql.ToString(), null, Get_TrxName()); DataTable dt = new DataTable(); dt.Load(idr); idr.Close(); foreach (DataRow dr in dt.Rows) { MOrderLine ol = new MOrderLine(GetCtx(), dr, Get_TrxName()); list.Add(ol); } } catch (Exception e) { log.Log(Level.SEVERE, sql.ToString(), e); } finally { if (idr != null) { idr.Close(); idr = null; } } // MOrderLine[] lines = new MOrderLine[list.Count];; lines = list.ToArray(); return(lines); }
/// <summary> /// Before Delete /// </summary> /// <returns>true if acct was deleted</returns> protected override bool BeforeDelete() { if (IsPosted()) { if (!MPeriod.IsOpen(GetCtx(), GetDateTrx(), MDocBaseType.DOCBASETYPE_MATCHPO)) { return(false); } SetPosted(false); return(true);// MFactAcct.Delete(Table_ID, Get_ID(), Get_Trx()) >= 0; } //JID_0162: System should allow to delete the Matched PO of PO and MR with complete status only. if (GetC_OrderLine_ID() != 0) { MOrderLine line = new MOrderLine(GetCtx(), GetC_OrderLine_ID(), Get_TrxName()); MOrder ord = new MOrder(GetCtx(), line.GetC_Order_ID(), Get_TrxName()); if (ord.GetDocStatus() != DocumentEngine.ACTION_COMPLETE) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "Order/ShipmentNotCompleted")); return(false); } } if (GetM_InOutLine_ID() != 0) { MInOutLine line = new MInOutLine(GetCtx(), GetM_InOutLine_ID(), Get_TrxName()); MInOut ino = new MInOut(GetCtx(), line.GetM_InOut_ID(), Get_TrxName()); if (ino.GetDocStatus() != DocumentEngine.ACTION_COMPLETE) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "Order/ShipmentNotCompleted")); return(false); } } return(true); }
/// <summary> /// Generate Quotation /// </summary> /// <returns>Process Message</returns> protected override string DoIt() { // Int32 value = 0; string msg = ""; ValueNamePair vp = null; MBPartner bp = null; MOrderLine ol = null; log.Info("C_Project_ID=" + _C_Project_ID); if (_C_Project_ID == 0) { throw new ArgumentException("C_Project_ID == 0"); } MProject fromProject = new MProject(GetCtx(), _C_Project_ID, Get_TrxName()); if (fromProject.GetGenerate_Quotation() == null) { throw new ArgumentException("No Generate Quotation found on Project."); } if (fromProject.GetGenerate_Quotation().Trim() == "Y") { throw new ArgumentException("Sales Quotation already generated"); } // if Business Partner or Prospect is not selected then gives error if (fromProject.GetC_BPartner_ID() == 0 && fromProject.GetC_BPartnerSR_ID() == 0) { return(Msg.GetMsg(GetCtx(), "SelectBP/Prospect")); } //JID_1200: if Business Partner/Prospect Location is not selected then gives error if (fromProject.GetC_BPartner_Location_ID() == 0) { return(Msg.GetMsg(GetCtx(), "SelectBPLocation")); } MOrder order = new MOrder(GetCtx(), 0, Get_TrxName()); order.SetAD_Client_ID(fromProject.GetAD_Client_ID()); order.SetAD_Org_ID(fromProject.GetAD_Org_ID()); C_Bpartner_id = fromProject.GetC_BPartner_ID(); C_Bpartner_Location_id = fromProject.GetC_BPartner_Location_ID(); C_BPartnerSR_ID = fromProject.GetC_BPartnerSR_ID(); MBPartnerLocation bpartnerloc = new MBPartnerLocation(GetCtx(), C_Bpartner_Location_id, Get_TrxName()); //String currentdate = DateTime.Now.ToString(); String sqlprjln = "SELECT COUNT(C_ProjectLine_ID) FROM C_ProjectLine WHERE C_Project_ID=" + _C_Project_ID; C_ProjectLine_ID = Util.GetValueOfInt(DB.ExecuteScalar(sqlprjln, null, Get_TrxName())); if (C_ProjectLine_ID != 0) { order.SetDateOrdered(DateTime.Now.ToLocalTime()); order.SetDatePromised(DateTime.Now.ToLocalTime()); if (C_Bpartner_id != 0) { order.SetC_BPartner_ID(fromProject.GetC_BPartner_ID()); if (bpartnerloc.IsShipTo() == true) { order.SetC_BPartner_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetAD_User_ID(fromProject.GetAD_User_ID()); } if (bpartnerloc.IsBillTo() == true) { order.SetBill_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetBill_User_ID(fromProject.GetAD_User_ID()); } } if (C_BPartnerSR_ID != 0) { order.SetC_BPartner_ID(fromProject.GetC_BPartnerSR_ID()); if (bpartnerloc.IsShipTo() == true) { order.SetC_BPartner_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetAD_User_ID(fromProject.GetAD_User_ID()); } if (bpartnerloc.IsBillTo() == true) { order.SetBill_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetBill_User_ID(fromProject.GetAD_User_ID()); } } String sql = "SELECT C_DocType_ID FROM C_DocType WHERE DocBaseType = 'SOO' AND DocSubTypeSO = 'ON' AND IsReturnTrx = 'N' AND IsActive = 'Y' AND AD_Client_ID = " + GetCtx().GetAD_Client_ID() + " AND AD_Org_ID IN (0, " + GetAD_Org_ID() + ") ORDER BY AD_Org_ID DESC"; int Doctype_id = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_TrxName())); int MPriceList_id = fromProject.GetM_PriceList_ID(); order.SetM_PriceList_ID(MPriceList_id); order.SetC_Project_ID(GetRecord_ID()); if (fromProject.GetSalesRep_ID() > 0) { order.SetSalesRep_ID(fromProject.GetSalesRep_ID()); } order.SetC_Currency_ID(fromProject.GetC_Currency_ID()); if (C_Bpartner_id != 0) { bp = new MBPartner(GetCtx(), C_Bpartner_id, Get_TrxName()); if (bp.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0) { bp.SetC_Campaign_ID(fromProject.GetC_Campaign_ID()); } //bp.SetAD_Client_ID(fromProject.GetAD_Client_ID()); //bp.SetAD_Org_ID(fromProject.GetAD_Org_ID()); if (bp.GetC_PaymentTerm_ID() != 0) { order.SetPaymentMethod(bp.GetPaymentRule()); order.SetC_PaymentTerm_ID(bp.GetC_PaymentTerm_ID()); order.SetVA009_PaymentMethod_ID(bp.GetVA009_PaymentMethod_ID()); } if (!bp.Save()) { log.SaveError("BPartnerNotSaved", ""); return(Msg.GetMsg(GetCtx(), "BPartnerNotSaved")); } } else { bp = new MBPartner(GetCtx(), C_BPartnerSR_ID, Get_TrxName()); if (bp.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0) { bp.SetC_Campaign_ID(fromProject.GetC_Campaign_ID()); } //bp.SetAD_Client_ID(fromProject.GetAD_Client_ID()); //bp.SetAD_Org_ID(fromProject.GetAD_Org_ID()); if (bp.GetC_PaymentTerm_ID() != 0) { order.SetPaymentMethod(bp.GetPaymentRule()); order.SetC_PaymentTerm_ID(bp.GetC_PaymentTerm_ID()); order.SetVA009_PaymentMethod_ID(bp.GetVA009_PaymentMethod_ID()); } if (!bp.Save()) { log.SaveError("BPartnerNotSaved", ""); return(Msg.GetMsg(GetCtx(), "BPartnerNotSaved")); } } order.SetFreightCostRule("I"); if (order.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0) { order.SetC_Campaign_ID(fromProject.GetC_Campaign_ID()); } order.SetDocStatus("IP"); order.SetC_DocType_ID(Doctype_id); order.SetC_DocTypeTarget_ID(Doctype_id); order.SetIsSOTrx(true); order.Set_Value("IsSalesQuotation", true); //Set VA077 values on header level if (Env.IsModuleInstalled("VA077_")) { //Get the org count of legal entity org sql = @"SELECT Count(AD_Org_ID) FROM AD_Org WHERE IsActive='Y' AND (IsProfitCenter ='Y' OR IsCostCenter ='Y') AND AD_Client_Id=" + fromProject.GetAD_Client_ID() + @" AND LegalEntityOrg = " + fromProject.GetAD_Org_ID(); int result = Util.GetValueOfInt(DB.ExecuteScalar(sql)); if (result > 0) { order.SetVA077_IsLegalEntity(true); } order.SetVA077_SalesCoWorker(fromProject.GetVA077_SalesCoWorker()); order.SetVA077_SalesCoWorkerPer(fromProject.GetVA077_SalesCoWorkerPer()); order.Set_Value("VA077_TotalMarginAmt", fromProject.Get_Value("VA077_TotalMarginAmt")); order.Set_Value("VA077_TotalPurchaseAmt", fromProject.Get_Value("VA077_TotalPurchaseAmt")); order.Set_Value("VA077_TotalSalesAmt", fromProject.Get_Value("VA077_TotalSalesAmt")); order.Set_Value("VA077_MarginPercent", fromProject.Get_Value("VA077_MarginPercent")); } if (!order.Save()) { Get_TrxName().Rollback(); vp = VLogger.RetrieveError(); if (vp != null) { msg = vp.GetName(); } else { msg = Msg.GetMsg(GetCtx(), "QuotationNotSaved"); } log.SaveError("QuotationNotSaved", ""); return(msg); } //Order Lines int count = 0; MProjectLine[] lines = fromProject.GetLines(); for (int i = 0; i < lines.Length; i++) { ol = new MOrderLine(order); ol.SetLine(lines[i].GetLine()); ol.SetDescription(lines[i].GetDescription()); ol.SetM_Product_ID(lines[i].GetM_Product_ID(), true); ol.SetQtyEntered(lines[i].GetPlannedQty()); ol.SetQtyOrdered(lines[i].GetPlannedQty()); ol.SetPriceEntered(lines[i].GetPlannedPrice()); ol.SetPriceActual(lines[i].GetPlannedPrice()); ol.SetPriceList(lines[i].GetPriceList()); //Set VA077 values on line level if (Env.IsModuleInstalled("VA077_")) { ol.Set_Value("VA077_MarginPercent", lines[i].Get_Value("VA077_MarginPercent")); ol.Set_Value("VA077_MarginAmt", lines[i].Get_Value("VA077_MarginAmt")); ol.Set_Value("VA077_PurchasePrice", lines[i].Get_Value("VA077_PurchasePrice")); } if (ol.Save()) { count++; } else { Get_TrxName().Rollback(); vp = VLogger.RetrieveError(); if (vp != null) { msg = vp.GetName(); } else { msg = Msg.GetMsg(GetCtx(), "QuoteLineNotSaved"); } log.SaveError("QuoteLineNotSaved", ""); return(msg); } } fromProject.SetRef_Order_ID(order.GetC_Order_ID()); fromProject.SetGenerate_Quotation("Y"); if (!fromProject.Save()) { Get_TrxName().Rollback(); log.SaveError("ProjectNotSaved", ""); return(Msg.GetMsg(GetCtx(), "ProjectNotSaved")); } msg = Msg.GetMsg(GetCtx(), "QuotationGenerated"); } else { msg = Msg.GetMsg(GetCtx(), "NoLines"); } return(msg); }
/** * 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); }
public bool SetProductQty(int recordID, string keyColName, List <string> product, List <string> attribute, List <string> qty, List <string> qtybook, List <string> oline_ID, int ordID, List <string> locID, int lineID, VAdvantage.Utility.Ctx ctx) { if (keyColName.ToUpper().Trim() == "C_ORDER_ID") { MOrder ord = new MOrder(ctx, recordID, null); for (int i = 0; i < product.Count; i++) { MOrderLine oline = new MOrderLine(ctx, lineID, null); oline.SetAD_Client_ID(ord.GetAD_Client_ID()); oline.SetAD_Org_ID(ord.GetAD_Org_ID()); oline.SetM_Product_ID(Util.GetValueOfInt(product[i])); oline.SetQty(Util.GetValueOfDecimal(qty[i])); oline.SetC_Order_ID(recordID); if (Util.GetValueOfInt(attribute[i]) != 0) { oline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i])); } if (!ord.IsSOTrx()) { MProduct pro = new MProduct(ctx, oline.GetM_Product_ID(), null); String qryUom = "SELECT vdr.C_UOM_ID FROM M_Product p LEFT JOIN M_Product_Po vdr ON p.M_Product_ID= vdr.M_Product_ID WHERE p.M_Product_ID=" + oline.GetM_Product_ID() + " AND vdr.C_BPartner_ID = " + ord.GetC_BPartner_ID(); int uom = Util.GetValueOfInt(DB.ExecuteScalar(qryUom)); if (pro.GetC_UOM_ID() != 0) { if (pro.GetC_UOM_ID() != uom && uom != 0) { decimal?Res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND M_Product_ID= " + oline.GetM_Product_ID() + " AND IsActive='Y'")); if (Res > 0) { oline.SetQtyEntered(oline.GetQtyEntered() * Res); //OrdQty = MUOMConversion.ConvertProductTo(GetCtx(), _M_Product_ID, UOM, OrdQty); } else { decimal?res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND IsActive='Y'")); if (res > 0) { oline.SetQtyEntered(oline.GetQtyEntered() * res); //OrdQty = MUOMConversion.Convert(GetCtx(), prdUOM, UOM, OrdQty); } } oline.SetC_UOM_ID(uom); } else { oline.SetC_UOM_ID(pro.GetC_UOM_ID()); } } } if (!oline.Save()) { } } } else if (keyColName.ToUpper().Trim() == "C_INVOICE_ID") { MInvoice inv = new MInvoice(ctx, recordID, null); for (int i = 0; i < product.Count; i++) { MInvoiceLine invline = new MInvoiceLine(ctx, lineID, null); invline.SetAD_Client_ID(inv.GetAD_Client_ID()); invline.SetAD_Org_ID(inv.GetAD_Org_ID()); invline.SetM_Product_ID(Util.GetValueOfInt(product[i])); invline.SetQty(Util.GetValueOfDecimal(qty[i])); invline.SetC_Invoice_ID(recordID); if (Util.GetValueOfInt(attribute[i]) != 0) { invline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i])); } if (!inv.IsSOTrx()) { MProduct pro = new MProduct(ctx, invline.GetM_Product_ID(), null); String qryUom = "SELECT vdr.C_UOM_ID FROM M_Product p LEFT JOIN M_Product_Po vdr ON p.M_Product_ID= vdr.M_Product_ID WHERE p.M_Product_ID=" + invline.GetM_Product_ID() + " AND vdr.C_BPartner_ID = " + inv.GetC_BPartner_ID(); int uom = Util.GetValueOfInt(DB.ExecuteScalar(qryUom)); if (pro.GetC_UOM_ID() != 0) { if (pro.GetC_UOM_ID() != uom && uom != 0) { decimal?Res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND M_Product_ID= " + invline.GetM_Product_ID() + " AND IsActive='Y'")); if (Res > 0) { invline.SetQtyEntered(invline.GetQtyEntered() * Res); //OrdQty = MUOMConversion.ConvertProductTo(GetCtx(), _M_Product_ID, UOM, OrdQty); } else { decimal?res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND IsActive='Y'")); if (res > 0) { invline.SetQtyEntered(invline.GetQtyEntered() * res); //OrdQty = MUOMConversion.Convert(GetCtx(), prdUOM, UOM, OrdQty); } } invline.SetC_UOM_ID(uom); } else { invline.SetC_UOM_ID(pro.GetC_UOM_ID()); } } } if (!invline.Save()) { } } } else if (keyColName.ToUpper().Trim() == "M_INOUT_ID") { MInOut inv = new MInOut(ctx, recordID, null); if (ordID > 0) { inv.SetC_Order_ID(ordID); } if (inv.Save()) { for (int i = 0; i < product.Count; i++) { MInOutLine ioline = new MInOutLine(ctx, lineID, null); ioline.SetAD_Client_ID(inv.GetAD_Client_ID()); ioline.SetAD_Org_ID(inv.GetAD_Org_ID()); ioline.SetM_Product_ID(Util.GetValueOfInt(product[i])); ioline.SetQty(Util.GetValueOfDecimal(qty[i])); ioline.SetM_InOut_ID(recordID); ioline.SetC_OrderLine_ID(Util.GetValueOfInt(oline_ID[i])); ioline.SetM_Locator_ID(Util.GetValueOfInt(locID[i])); if (Util.GetValueOfInt(attribute[i]) != 0) { ioline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i])); } if (!inv.IsSOTrx()) { MProduct pro = new MProduct(ctx, ioline.GetM_Product_ID(), null); String qryUom = "SELECT vdr.C_UOM_ID FROM M_Product p LEFT JOIN M_Product_Po vdr ON p.M_Product_ID= vdr.M_Product_ID WHERE p.M_Product_ID=" + ioline.GetM_Product_ID() + " AND vdr.C_BPartner_ID = " + inv.GetC_BPartner_ID(); int uom = Util.GetValueOfInt(DB.ExecuteScalar(qryUom)); if (pro.GetC_UOM_ID() != 0) { if (pro.GetC_UOM_ID() != uom && uom != 0) { decimal?Res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND M_Product_ID= " + ioline.GetM_Product_ID() + " AND IsActive='Y'")); if (Res > 0) { ioline.SetQtyEntered(ioline.GetQtyEntered() * Res); //OrdQty = MUOMConversion.ConvertProductTo(GetCtx(), _M_Product_ID, UOM, OrdQty); } else { decimal?res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND IsActive='Y'")); if (res > 0) { ioline.SetQtyEntered(ioline.GetQtyEntered() * res); //OrdQty = MUOMConversion.Convert(GetCtx(), prdUOM, UOM, OrdQty); } } ioline.SetC_UOM_ID(uom); } else { ioline.SetC_UOM_ID(pro.GetC_UOM_ID()); } } } if (!ioline.Save()) { } } } } else if (keyColName.ToUpper().Trim() == "M_PACKAGE_ID") { MPackage pkg = new MPackage(ctx, recordID, null); for (int i = 0; i < product.Count; i++) { MPackageLine mline = new MPackageLine(ctx, lineID, null); mline.SetAD_Client_ID(pkg.GetAD_Client_ID()); mline.SetAD_Org_ID(pkg.GetAD_Org_ID()); mline.SetM_Product_ID(Util.GetValueOfInt(product[i])); mline.SetQty(Util.GetValueOfDecimal(qty[i])); if (Util.GetValueOfInt(oline_ID[i]) > 0) { mline.SetM_MovementLine_ID(Util.GetValueOfInt(oline_ID[i])); MMovementLine mov = new MMovementLine(ctx, Util.GetValueOfInt(oline_ID[i]), null); mline.SetDTD001_TotalQty(mov.GetMovementQty()); } if (Util.GetValueOfInt(attribute[i]) != 0) { mline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i])); } mline.SetM_Package_ID(recordID); if (!mline.Save()) { } } } else if (keyColName.ToUpper().Trim() == "M_INVENTORY_ID") { MInventory inv = new MInventory(ctx, recordID, null); for (int i = 0; i < product.Count; i++) { MInventoryLine invline = new MInventoryLine(ctx, lineID, null); invline.SetAD_Client_ID(inv.GetAD_Client_ID()); invline.SetAD_Org_ID(inv.GetAD_Org_ID()); invline.SetM_Locator_ID(Util.GetValueOfInt(locID[i])); invline.SetM_Product_ID(Util.GetValueOfInt(product[i])); invline.SetQtyCount(Util.GetValueOfDecimal(qty[i])); invline.SetQtyBook(Util.GetValueOfDecimal(qtybook[i])); invline.SetAsOnDateCount(Util.GetValueOfDecimal(qty[i])); invline.SetOpeningStock(Util.GetValueOfDecimal(qtybook[i])); invline.SetM_Inventory_ID(recordID); if (Util.GetValueOfInt(attribute[i]) != 0) { invline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i])); } else { invline.SetM_AttributeSetInstance_ID(0); } if (!invline.Save()) { } } } return(true); }
/// <summary> /// New Order Line (different Product) /// </summary> /// <param name="rLine">request line</param> private void NewLine(MRequisitionLine rLine) { if (_orderLine != null) { if (!_orderLine.Save()) { throw new Exception("Cannot update Order Line"); } } _orderLine = null; MProduct product = null; // Get Business Partner int C_BPartner_ID = rLine.GetC_BPartner_ID(); if (C_BPartner_ID != 0) { ; } else if (rLine.GetC_Charge_ID() != 0) { MCharge charge = MCharge.Get(GetCtx(), rLine.GetC_Charge_ID()); C_BPartner_ID = charge.GetC_BPartner_ID(); if (C_BPartner_ID == 0) { throw new Exception("No Vendor for Charge " + charge.GetName()); } } else { // Find Vendor from Produt product = MProduct.Get(GetCtx(), rLine.GetM_Product_ID()); MProductPO[] ppos = MProductPO.GetOfProduct(GetCtx(), product.GetM_Product_ID(), null); for (int i = 0; i < ppos.Length; i++) { if (ppos[i].IsCurrentVendor() && ppos[i].GetC_BPartner_ID() != 0) { C_BPartner_ID = ppos[i].GetC_BPartner_ID(); break; } } if (C_BPartner_ID == 0 && ppos.Length > 0) { C_BPartner_ID = ppos[0].GetC_BPartner_ID(); } if (C_BPartner_ID == 0) { throw new Exception("No Vendor for " + product.GetName()); } } // New Order - Different Vendor if (_order == null || _order.GetC_BPartner_ID() != C_BPartner_ID) { NewOrder(rLine, C_BPartner_ID); } // No Order Line _orderLine = new MOrderLine(_order); if (product != null) { _orderLine.SetProduct(product); _orderLine.SetM_AttributeSetInstance_ID(rLine.GetM_AttributeSetInstance_ID()); } else { _orderLine.SetC_Charge_ID(rLine.GetC_Charge_ID()); _orderLine.SetPriceActual(rLine.GetPriceActual()); } _orderLine.SetAD_Org_ID(rLine.GetAD_Org_ID()); // Prepare Save _m_M_Product_ID = rLine.GetM_Product_ID(); _m_M_AttributeSetInstance_ID = rLine.GetM_AttributeSetInstance_ID(); if (!_orderLine.Save()) { throw new Exception("Cannot save Order Line"); } }
} // doIt /// <summary> /// Process Expense Line /// </summary> /// <param name="te">header</param> /// <param name="tel">line</param> /// <param name="bp">bp</param> private void ProcessLine(MTimeExpense te, MTimeExpenseLine tel, MBPartner bp) { if (_order == null) { log.Info("New Order for " + bp + ", Project=" + tel.GetC_Project_ID()); _order = new MOrder(GetCtx(), 0, Get_TrxName()); _order.SetAD_Org_ID(tel.GetAD_Org_ID()); _order.SetC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard); // _order.SetBPartner(bp); if (_order.GetC_BPartner_Location_ID() == 0) { log.Log(Level.SEVERE, "No BP Location: " + bp); AddLog(0, te.GetDateReport(), null, "No Location: " + te.GetDocumentNo() + " " + bp.GetName()); _order = null; return; } _order.SetM_Warehouse_ID(te.GetM_Warehouse_ID()); ////Added By Arpit asked by Surya Sir..................29-12-2015 //_order.SetSalesRep_ID(GetCtx().GetAD_User_ID()); //End if (tel.GetC_Activity_ID() != 0) { _order.SetC_Activity_ID(tel.GetC_Activity_ID()); } if (tel.GetC_Campaign_ID() != 0) { _order.SetC_Campaign_ID(tel.GetC_Campaign_ID()); } if (tel.GetC_Project_ID() != 0) { _order.SetC_Project_ID(tel.GetC_Project_ID()); // Optionally Overwrite BP Price list from Project MProject project = new MProject(GetCtx(), tel.GetC_Project_ID(), Get_TrxName()); if (project.GetM_PriceList_ID() != 0) { _order.SetM_PriceList_ID(project.GetM_PriceList_ID()); } } _order.SetSalesRep_ID(te.GetDoc_User_ID()); // if (!_order.Save()) { throw new Exception("Cannot save Order"); } } else { // Update Header info if (tel.GetC_Activity_ID() != 0 && tel.GetC_Activity_ID() != _order.GetC_Activity_ID()) { _order.SetC_Activity_ID(tel.GetC_Activity_ID()); } if (tel.GetC_Campaign_ID() != 0 && tel.GetC_Campaign_ID() != _order.GetC_Campaign_ID()) { _order.SetC_Campaign_ID(tel.GetC_Campaign_ID()); } if (!_order.Save()) { new Exception("Cannot save Order"); } } // OrderLine MOrderLine ol = new MOrderLine(_order); // if (tel.GetM_Product_ID() != 0) { ol.SetM_Product_ID(tel.GetM_Product_ID(), tel.GetC_UOM_ID()); } if (tel.GetS_ResourceAssignment_ID() != 0) { ol.SetS_ResourceAssignment_ID(tel.GetS_ResourceAssignment_ID()); } // Set charge ID if (tel.GetC_Charge_ID() != 0) { ol.SetC_Charge_ID(tel.GetC_Charge_ID()); ol.SetPriceActual(tel.GetExpenseAmt()); ol.SetQty(tel.GetQty()); } ol.SetQty(tel.GetQtyInvoiced()); // ol.SetDescription(tel.GetDescription()); // ol.SetC_Project_ID(tel.GetC_Project_ID()); ol.SetC_ProjectPhase_ID(tel.GetC_ProjectPhase_ID()); ol.SetC_ProjectTask_ID(tel.GetC_ProjectTask_ID()); ol.SetC_Activity_ID(tel.GetC_Activity_ID()); ol.SetC_Campaign_ID(tel.GetC_Campaign_ID()); // Decimal price = tel.GetPriceInvoiced(); // if (price.CompareTo(Env.ZERO) != 0) { if (tel.GetC_Currency_ID() != _order.GetC_Currency_ID()) { price = MConversionRate.Convert(GetCtx(), price, tel.GetC_Currency_ID(), _order.GetC_Currency_ID(), _order.GetAD_Client_ID(), _order.GetAD_Org_ID()); } ol.SetPrice(price); } else { ol.SetPrice(); } if (tel.GetC_UOM_ID() != 0 && ol.GetC_UOM_ID() == 0) { ol.SetC_UOM_ID(tel.GetC_UOM_ID()); } ol.SetTax(); if (!ol.Save()) { throw new Exception("Cannot save Order Line"); } // Update TimeExpense Line tel.SetC_OrderLine_ID(ol.GetC_OrderLine_ID()); if (tel.Save()) { log.Fine("Updated " + tel + " with C_OrderLine_ID"); } else { log.Log(Level.SEVERE, "Not Updated " + tel + " with C_OrderLine_ID"); } } // processLine
/// <summary> /// Create PO From SO /// </summary> /// <param name="so">sales order</param> /// <returns>number of POs created</returns> private int CreatePOFromSO(MOrder so) { log.Info(so.ToString()); MOrderLine[] soLines = so.GetLines(true, null); if (soLines == null || soLines.Length == 0) { log.Warning("No Lines - " + so); return(0); } // int counter = 0; // Order Lines with a Product which has a current vendor String sql = "SELECT DISTINCT po.C_BPartner_ID, po.M_Product_ID " + "FROM M_Product_PO po" + " INNER JOIN C_OrderLine ol ON (po.M_Product_ID=ol.M_Product_ID) " + "WHERE ol.C_Order_ID=" + so.GetC_Order_ID() + " AND po.IsCurrentVendor='Y' " + "ORDER BY 1"; IDataReader idr = null; MOrder po = null; try { idr = DataBase.DB.ExecuteReader(sql, null, Get_TrxName()); while (idr.Read()) { // New Order int C_BPartner_ID = Utility.Util.GetValueOfInt(idr[0]);//.getInt(1); if (po == null || po.GetBill_BPartner_ID() != C_BPartner_ID) { po = CreatePOForVendor(Utility.Util.GetValueOfInt(idr[0]), so); AddLog(0, null, null, po.GetDocumentNo()); counter++; } // Line int M_Product_ID = Utility.Util.GetValueOfInt(idr[1]);//.getInt(2); for (int i = 0; i < soLines.Length; i++) { if (soLines[i].GetM_Product_ID() == M_Product_ID) { MOrderLine poLine = new MOrderLine(po); poLine.SetRef_OrderLine_ID(soLines[i].GetC_OrderLine_ID()); poLine.SetM_Product_ID(soLines[i].GetM_Product_ID()); poLine.SetM_AttributeSetInstance_ID(soLines[i].GetM_AttributeSetInstance_ID()); poLine.SetC_UOM_ID(soLines[i].GetC_UOM_ID()); poLine.SetQtyEntered(soLines[i].GetQtyEntered()); poLine.SetQtyOrdered(soLines[i].GetQtyOrdered()); poLine.SetDescription(soLines[i].GetDescription()); poLine.SetDatePromised(soLines[i].GetDatePromised()); poLine.SetPrice(); poLine.Save(); } } } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, sql, e); } // Set Reference to PO if (counter == 1 && po != null) { so.SetRef_Order_ID(po.GetC_Order_ID()); so.Save(); } return(counter); }
/// <summary> /// Process. /// A Sales Order is created for the entered Business Partner. /// A sales order line is created for each RfQ line quantity, /// where "Offer Quantity" is selected. /// If on the RfQ Line Quantity, an offer amount is entered (not 0), /// that price is used. /// If a magin is entered on RfQ Line Quantity, it overwrites the /// general margin. The margin is the percentage added to the /// Best Response Amount. /// </summary> /// <returns>message</returns> protected override String DoIt() { MRfQ rfq = new MRfQ(GetCtx(), _C_RfQ_ID, Get_TrxName()); if (rfq.Get_ID() == 0) { throw new ArgumentException("No RfQ found"); } log.Info("doIt - " + rfq); if (rfq.GetC_BPartner_ID() == 0 || rfq.GetC_BPartner_Location_ID() == 0) { throw new Exception("No Business Partner/Location"); } MBPartner bp = new MBPartner(GetCtx(), rfq.GetC_BPartner_ID(), Get_TrxName()); MOrder order = new MOrder(GetCtx(), 0, Get_TrxName()); order.SetIsSOTrx(true); if (_C_DocType_ID != 0) { order.SetC_DocTypeTarget_ID(_C_DocType_ID); } else { order.SetC_DocTypeTarget_ID(); } order.SetBPartner(bp); order.SetC_BPartner_Location_ID(rfq.GetC_BPartner_Location_ID()); order.SetSalesRep_ID(rfq.GetSalesRep_ID()); if (rfq.GetDateWorkComplete() != null) { order.SetDatePromised(rfq.GetDateWorkComplete()); } order.Save(); MRfQLine[] lines = rfq.GetLines(); for (int i = 0; i < lines.Length; i++) { MRfQLine line = lines[i]; MRfQLineQty[] qtys = line.GetQtys(); for (int j = 0; j < qtys.Length; j++) { MRfQLineQty qty = qtys[j]; if (qty.IsActive() && qty.IsOfferQty()) { MOrderLine ol = new MOrderLine(order); ol.SetM_Product_ID(line.GetM_Product_ID(), qty.GetC_UOM_ID()); ol.SetDescription(line.GetDescription()); ol.SetQty(qty.GetQty()); // Decimal price = qty.GetOfferAmt(); if (Env.Signum(price) == 0) { price = qty.GetBestResponseAmt(); if (Env.Signum(price) == 0) { price = Env.ZERO; log.Warning(" - BestResponse=0 - " + qty); } else { Decimal margin = qty.GetMargin(); if (Env.Signum(margin) == 0) { margin = rfq.GetMargin(); } if (Env.Signum(margin) != 0) { margin = Decimal.Add(margin, ONEHUNDRED); price = Decimal.Round(Decimal.Divide(Decimal.Multiply(price, margin), ONEHUNDRED), 2, MidpointRounding.AwayFromZero); } } } // price ol.SetPrice(price); ol.Save(); } // Offer Qty } // All Qtys } // All Lines rfq.SetC_Order_ID(order.GetC_Order_ID()); rfq.Save(); return(order.GetDocumentNo()); }
/// <summary> /// Process. /// Create purchase order(s) for the resonse(s) and lines marked as /// Selected Winner using the selected Purchase Quantity (in RfQ Line Quantity) . /// If a Response is marked as Selected Winner, all lines are created /// (and Selected Winner of other responses ignored). /// If there is no response marked as Selected Winner, the lines are used. /// </summary> /// <returns>message</returns> protected override String DoIt() { MRfQ rfq = new MRfQ(GetCtx(), _C_RfQ_ID, Get_TrxName()); if (rfq.Get_ID() == 0) { throw new ArgumentException("No RfQ found"); } log.Info(rfq.ToString()); // Complete MRfQResponse[] responses = rfq.GetResponses(true, true); log.Config("#Responses=" + responses.Length); if (responses.Length == 0) { throw new ArgumentException("No completed RfQ Responses found"); } // Winner for entire RfQ for (int i = 0; i < responses.Length; i++) { MRfQResponse response = responses[i]; if (!response.IsSelectedWinner()) { continue; } // MBPartner bp = new MBPartner(GetCtx(), response.GetC_BPartner_ID(), Get_TrxName()); log.Config("Winner=" + bp); MOrder order = new MOrder(GetCtx(), 0, Get_TrxName()); order.SetIsSOTrx(false); if (_C_DocType_ID != 0) { order.SetC_DocTypeTarget_ID(_C_DocType_ID); } else { order.SetC_DocTypeTarget_ID(); } order.SetBPartner(bp); order.SetC_BPartner_Location_ID(response.GetC_BPartner_Location_ID()); order.SetSalesRep_ID(rfq.GetSalesRep_ID()); if (response.GetDateWorkComplete() != null) { order.SetDatePromised(response.GetDateWorkComplete()); } else if (rfq.GetDateWorkComplete() != null) { order.SetDatePromised(rfq.GetDateWorkComplete()); } order.Save(); // MRfQResponseLine[] lines = response.GetLines(false); for (int j = 0; j < lines.Length; j++) { // Respones Line MRfQResponseLine line = lines[j]; if (!line.IsActive()) { continue; } MRfQResponseLineQty[] qtys = line.GetQtys(false); // Response Line Qty for (int k = 0; k < qtys.Length; k++) { MRfQResponseLineQty qty = qtys[k]; // Create PO Lline for all Purchase Line Qtys if (qty.GetRfQLineQty().IsActive() && qty.GetRfQLineQty().IsPurchaseQty()) { MOrderLine ol = new MOrderLine(order); ol.SetM_Product_ID(line.GetRfQLine().GetM_Product_ID(), qty.GetRfQLineQty().GetC_UOM_ID()); ol.SetDescription(line.GetDescription()); ol.SetQty(qty.GetRfQLineQty().GetQty()); Decimal?price = qty.GetNetAmt(); ol.SetPrice(price == null?Env.ZERO:price.Value); ol.Save(); } } } response.SetC_Order_ID(order.GetC_Order_ID()); response.Save(); return(order.GetDocumentNo()); } // Selected Winner on Line Level int noOrders = 0; for (int i = 0; i < responses.Length; i++) { MRfQResponse response = responses[i]; MBPartner bp = null; MOrder order = null; // For all Response Lines MRfQResponseLine[] lines = response.GetLines(false); for (int j = 0; j < lines.Length; j++) { MRfQResponseLine line = lines[j]; if (!line.IsActive() || !line.IsSelectedWinner()) { continue; } // New/different BP if (bp == null) { bp = new MBPartner(GetCtx(), response.GetC_BPartner_ID(), Get_TrxName()); order = null; } log.Config("Line=" + line + ", Winner=" + bp); // New Order if (order == null) { order = new MOrder(GetCtx(), 0, Get_TrxName()); order.SetIsSOTrx(false); order.SetC_DocTypeTarget_ID(); order.SetBPartner(bp); order.SetC_BPartner_Location_ID(response.GetC_BPartner_Location_ID()); order.SetSalesRep_ID(rfq.GetSalesRep_ID()); order.Save(); noOrders++; //AddLog(0, null, null, order.GetDocumentNo()); AddLog(0, DateTime.Now, null, order.GetDocumentNo()); } // For all Qtys MRfQResponseLineQty[] qtys = line.GetQtys(false); for (int k = 0; k < qtys.Length; k++) { MRfQResponseLineQty qty = qtys[k]; if (qty.GetRfQLineQty().IsActive() && qty.GetRfQLineQty().IsPurchaseQty()) { MOrderLine ol = new MOrderLine(order); ol.SetM_Product_ID(line.GetRfQLine().GetM_Product_ID(), qty.GetRfQLineQty().GetC_UOM_ID()); ol.SetDescription(line.GetDescription()); ol.SetQty(qty.GetRfQLineQty().GetQty()); Decimal?price = qty.GetNetAmt(); ol.SetPriceActual(price); ol.Save(); } } // for all Qtys } // for all Response Lines if (order != null) { response.SetC_Order_ID(order.GetC_Order_ID()); response.Save(); } } return("#" + noOrders); }
/// <summary> /// Create Invoice Line from Order Line /// </summary> /// <param name="order">order</param> /// <param name="orderLine">line</param> /// <param name="qtyInvoiced">qty</param> /// <param name="qtyEntered">qty</param> private void CreateLine(MOrder order, MOrderLine orderLine, Decimal qtyInvoiced, Decimal qtyEntered) { if (_invoice == null) { _invoice = new MInvoice(order, 0, _DateInvoiced); int _CountVA009 = Env.IsModuleInstalled("VA009_") ? 1 : 0; if (_CountVA009 > 0) { int _PaymentMethod_ID = order.GetVA009_PaymentMethod_ID(); // Get Payment method from Business partner int bpPamentMethod_ID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT " + (order.IsSOTrx() ? " VA009_PaymentMethod_ID " : " VA009_PO_PaymentMethod_ID ") + @" FROM C_BPartner WHERE C_BPartner_ID = " + order.GetC_BPartner_ID(), null, Get_Trx())); // during consolidation, payment method need to set that is defined on selected business partner. // If not defined on BP then it will set from order if (_ConsolidateDocument && bpPamentMethod_ID != 0) { _PaymentMethod_ID = bpPamentMethod_ID; } if (_PaymentMethod_ID > 0) { _invoice.SetVA009_PaymentMethod_ID(_PaymentMethod_ID); } } int _CountVA026 = Env.IsModuleInstalled("VA026_") ? 1 : 0; if (_CountVA026 > 0) { _invoice.SetVA026_LCDetail_ID(order.GetVA026_LCDetail_ID()); } // Added by Bharat on 29 Jan 2018 to set Inco Term from Order if (_invoice.Get_ColumnIndex("C_IncoTerm_ID") > 0) { _invoice.SetC_IncoTerm_ID(order.GetC_IncoTerm_ID()); } if (Env.IsModuleInstalled("VA077_")) { //.setva077 _invoice.Set_Value("VA077_AdditionalAnnualCharge", order.Get_Value("VA077_AdditionalAnnualCharge")); _invoice.Set_Value("VA077_ChangeStartDate", order.Get_Value("VA077_ChangeStartDate")); _invoice.Set_Value("VA077_ContractCPEndDate", order.Get_Value("VA077_ContractCPEndDate")); _invoice.Set_Value("VA077_ContractCPStartDate", order.Get_Value("VA077_ContractCPStartDate")); _invoice.Set_Value("VA077_HistoricContractDate", order.Get_Value("VA077_HistoricContractDate")); _invoice.Set_Value("VA077_IsLegalEntity", order.Get_Value("VA077_IsLegalEntity")); _invoice.Set_Value("VA077_MarginPercent", order.Get_Value("VA077_MarginPercent")); _invoice.Set_Value("VA077_NewAnnualContractTotal", order.Get_Value("VA077_NewAnnualContractTotal")); _invoice.Set_Value("VA077_OldAnnualContractTotal", order.Get_Value("VA077_OldAnnualContractTotal")); _invoice.Set_Value("VA077_PartialAmtCatchUp", order.Get_Value("VA077_PartialAmtCatchUp")); _invoice.Set_Value("VA077_SalesCoWorker", order.Get_Value("VA077_SalesCoWorker")); _invoice.Set_Value("VA077_SalesCoWorkerPer", order.Get_Value("VA077_SalesCoWorkerPer")); _invoice.Set_Value("VA077_TotalMarginAmt", order.Get_Value("VA077_TotalMarginAmt")); _invoice.Set_Value("VA077_TotalPurchaseAmt", order.Get_Value("VA077_TotalPurchaseAmt")); _invoice.Set_Value("VA077_TotalSalesAmt", order.Get_Value("VA077_TotalSalesAmt")); } if (!_invoice.Save()) { ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Could not create Invoice (o). " + pp.GetName()); } throw new Exception("Could not create Invoice (o)"); } } // MInvoiceLine line = new MInvoiceLine(_invoice); line.SetOrderLine(orderLine); line.SetQtyInvoiced(qtyInvoiced); // if drop ship line true line.SetIsDropShip(orderLine.IsDropShip()); log.Info("Qty Invoiced" + line.GetQtyInvoiced()); line.SetQtyEntered(qtyEntered); line.SetLine(_line + orderLine.GetLine()); if (Env.IsModuleInstalled("VA077_")) { //invoice line line.Set_Value("VA077_CNAutodesk", orderLine.Get_Value("VA077_CNAutodesk")); line.Set_Value("VA077_Duration", orderLine.Get_Value("VA077_Duration")); line.Set_Value("VA077_MarginAmt", orderLine.Get_Value("VA077_MarginAmt")); line.Set_Value("VA077_MarginPercent", orderLine.Get_Value("VA077_MarginPercent")); line.Set_Value("VA077_OldSN", orderLine.Get_Value("VA077_OldSN")); line.Set_Value("VA077_ProductInfo", orderLine.Get_Value("VA077_ProductInfo")); line.Set_Value("VA077_PurchasePrice", orderLine.Get_Value("VA077_PurchasePrice")); line.Set_Value("VA077_RegEmail", orderLine.Get_Value("VA077_RegEmail")); line.Set_Value("VA077_SerialNo", orderLine.Get_Value("VA077_SerialNo")); line.Set_Value("VA077_UpdateFromVersn", orderLine.Get_Value("VA077_UpdateFromVersn")); line.Set_Value("VA077_UserRef_ID", orderLine.Get_Value("VA077_UserRef_ID")); line.Set_Value("VA077_StartDate", orderLine.Get_Value("VA077_StartDate")); line.Set_Value("VA077_EndDate", orderLine.Get_Value("VA077_EndDate")); } if (!line.Save()) { ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Could not create Invoice Line (o). " + pp.GetName()); } throw new Exception("Could not create Invoice Line (o)"); } log.Fine(line.ToString()); }
public static bool InsertForeignCostMatchOrder(Ctx ctx, MOrderLine orderLine, decimal matchQty, int ASI, Trx trx) { int acctSchema_ID = 0; int M_CostElement_ID = 0; int AD_Org_ID = 0; int M_ASI_ID = 0; MProduct product = null; MAcctSchema acctSchema = null; MCostForeignCurrency foreignCost = null; dynamic pc = null; String cl = null; MOrder order = null; try { order = new MOrder(ctx, orderLine.GetC_Order_ID(), trx); if (!order.IsSOTrx() && !order.IsReturnTrx()) { acctSchema_ID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT asch.c_acctschema_id FROM c_acctschema asch INNER JOIN ad_clientinfo ci ON ci.c_acctschema1_id = asch.c_acctschema_id WHERE ci.ad_client_id = " + order.GetAD_Client_ID())); acctSchema = new MAcctSchema(ctx, acctSchema_ID, trx); if (acctSchema.GetC_Currency_ID() != order.GetC_Currency_ID()) { // Get Costing Element of Av. PO M_CostElement_ID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT M_CostElement_ID FROM M_CostElement WHERE AD_Client_ID = " + order.GetAD_Client_ID() + " AND IsActive = 'Y' AND CostingMethod = 'A'")); product = new MProduct(ctx, orderLine.GetM_Product_ID(), trx); if (product != null && product.GetProductType() == "I" && product.GetM_Product_ID() > 0) // for Item Type product { pc = MProductCategory.Get(product.GetCtx(), product.GetM_Product_Category_ID()); // Get Costing Level if (pc != null) { cl = pc.GetCostingLevel(); } if (cl == null) { cl = acctSchema.GetCostingLevel(); } if (cl == "C" || cl == "B") { AD_Org_ID = 0; } else { AD_Org_ID = order.GetAD_Org_ID(); } if (cl != "B") { M_ASI_ID = 0; } else { M_ASI_ID = ASI; } foreignCost = MCostForeignCurrency.Get(product, M_ASI_ID, AD_Org_ID, M_CostElement_ID, order.GetC_BPartner_ID(), order.GetC_Currency_ID()); foreignCost.SetC_Order_ID(order.GetC_Order_ID()); foreignCost.SetCumulatedQty(Decimal.Add(foreignCost.GetCumulatedQty(), matchQty)); foreignCost.SetCumulatedAmt(Decimal.Add(foreignCost.GetCumulatedAmt(), Decimal.Multiply(orderLine.GetPriceActual(), matchQty))); if (foreignCost.GetCumulatedQty() != 0) { foreignCost.SetCostPerUnit(Decimal.Round(Decimal.Divide(foreignCost.GetCumulatedAmt(), foreignCost.GetCumulatedQty()), acctSchema.GetCostingPrecision())); } else { foreignCost.SetCostPerUnit(0); } if (!foreignCost.Save(trx)) { ValueNamePair pp = VLogger.RetrieveError(); _log.Severe("Error occured during updating M_Cost_ForeignCurrency. Error name : " + pp.GetName() + " AND Error Value : " + pp.GetValue() + " , For Invoice line : " + orderLine.GetC_OrderLine_ID() + " , AND Ad_Client_ID : " + orderLine.GetAD_Client_ID()); return(false); } } } } } catch (Exception ex) { _log.Log(Level.SEVERE, "", ex); return(false); } return(true); }
/// <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); }