/// <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); }
protected override string DoIt() { try { if (C_Order_ID < 1) { return("Failed"); } //int c_Order_ID = Util.GetValueOfInt(DB.ExecuteScalar("SELECT C_Order_ID From C_Order WHERE DocumentNo=" + salesOrderNo)); MOrder order = new MOrder(GetCtx(), C_Order_ID, null); int C_DocType_ID = order.GetC_DocTypeTarget_ID(); string baseType = DB.ExecuteScalar("SELECT DocSubTypeSO From C_DocType WHERE isactive='Y' AND C_DocType_ID=" + C_DocType_ID).ToString(); if (!(baseType.Equals("PR") || baseType.Equals("WI"))) { return("Failed"); } MPayment payment = new MPayment(GetCtx(), 0, null); payment.SetAD_Client_ID(GetCtx().GetAD_Client_ID()); payment.SetAD_Org_ID(GetCtx().GetAD_Org_ID()); //payment.SetDocumentNo(MS payment.SetC_BankAccount_ID(Util.GetValueOfInt( DB.ExecuteScalar("Select c_bankAccount_ID from c_bankaccount where isdefault='Y' and isactive='Y'"))); payment.SetDateTrx(DateTime.Now); payment.SetDateAcct(DateTime.Now); payment.SetC_BPartner_ID(order.GetC_BPartner_ID()); payment.SetPayAmt(order.GetGrandTotal()); payment.SetC_Currency_ID(order.GetC_Currency_ID()); payment.SetTenderType("K"); payment.SetDocStatus("IP"); if (baseType.Equals("PR")) //prepay Order { payment.SetC_Order_ID(order.GetC_Order_ID()); payment.SetIsPrepayment(true); } else if (baseType.Equals("WI"))//OnCreditOrder { payment.SetC_Invoice_ID(order.GetC_Invoice_ID()); } payment.Save(); return(payment.GetDocumentNo().ToString()); } catch { return("Failed"); } }
/// <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
/// <summary> /// Create PO for Vendor /// </summary> /// <param name="C_BPartner_ID">vendor</param> /// <param name="so">sales order</param> /// <returns>MOrder</returns> public MOrder CreatePOForVendor(int C_BPartner_ID, MOrder so) { MOrder po = new MOrder(GetCtx(), 0, Get_TrxName()); po.SetClientOrg(so.GetAD_Client_ID(), so.GetAD_Org_ID()); po.SetRef_Order_ID(so.GetC_Order_ID()); po.SetIsSOTrx(false); po.SetC_DocTypeTarget_ID(); // po.SetDescription(so.GetDescription()); po.SetPOReference(so.GetDocumentNo()); po.SetPriorityRule(so.GetPriorityRule()); po.SetSalesRep_ID(so.GetSalesRep_ID()); po.SetM_Warehouse_ID(so.GetM_Warehouse_ID()); // Set Vendor MBPartner vendor = new MBPartner(GetCtx(), C_BPartner_ID, Get_TrxName()); po.SetBPartner(vendor); // Drop Ship po.SetIsDropShip(so.IsDropShip()); if (so.IsDropShip()) { po.SetShip_BPartner_ID(so.GetC_BPartner_ID()); po.SetShip_Location_ID(so.GetC_BPartner_Location_ID()); po.SetShip_User_ID(so.GetAD_User_ID()); } // References po.SetC_Activity_ID(so.GetC_Activity_ID()); po.SetC_Campaign_ID(so.GetC_Campaign_ID()); po.SetC_Project_ID(so.GetC_Project_ID()); po.SetUser1_ID(so.GetUser1_ID()); po.SetUser2_ID(so.GetUser2_ID()); // po.Save(); return(po); }
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)); }
/// <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()); }
/// <summary> /// Create Invoice Line from Shipment /// </summary> /// <param name="order">order</param> /// <param name="ship">shipment header</param> /// <param name="sLine">shipment line</param> private void CreateLine(MOrder order, MInOut ship, MInOutLine sLine) { 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(); // 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 // during sale cycle -- VA009_PaymentMethod_ID // during purchase cycle -- VA009_PO_PaymentMethod_ID 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())); 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 (s). " + pp.GetName()); } throw new Exception("Could not create Invoice (s)"); } } #region Comment Create Shipment Comment Line // Create Shipment Comment Line //if (_ship == null // || _ship.GetM_InOut_ID() != ship.GetM_InOut_ID()) //{ // MDocType dt = MDocType.Get(GetCtx(), ship.GetC_DocType_ID()); // if (_bp == null || _bp.GetC_BPartner_ID() != ship.GetC_BPartner_ID()) // { // _bp = new MBPartner(GetCtx(), ship.GetC_BPartner_ID(), Get_TrxName()); // } // // Reference: Delivery: 12345 - 12.12.12 // MClient client = MClient.Get(GetCtx(), order.GetAD_Client_ID()); // String AD_Language = client.GetAD_Language(); // if (client.IsMultiLingualDocument() && _bp.GetAD_Language() != null) // { // AD_Language = _bp.GetAD_Language(); // } // if (AD_Language == null) // { // // MessageBox.Show("Set base Language"); // //AD_Language = Language.getBaseAD_Language(); // } // //java.text.SimpleDateFormat format = DisplayType.getDateFormat // // (DisplayType.Date, Language.getLanguage(AD_Language)); // //String reference = dt.GetPrintName(_bp.GetAD_Language()) // // + ": " + ship.GetDocumentNo() // // + " - " + format.format(ship.GetMovementDate()); // String reference = dt.GetPrintName(_bp.GetAD_Language()) // + ": " + ship.GetDocumentNo() // + " - " + ship.GetMovementDate(); // _ship = ship; // // // MInvoiceLine line = new MInvoiceLine(_invoice); // line.SetIsDescription(true); // line.SetDescription(reference); // line.SetLine(_line + sLine.GetLine() - 2); // if (!line.Save()) // { // throw new Exception("Could not create Invoice Comment Line (sh)"); // } // // Optional Ship Address if not Bill Address // if (order.GetBill_Location_ID() != ship.GetC_BPartner_Location_ID()) // { // MLocation addr = MLocation.GetBPLocation(GetCtx(), ship.GetC_BPartner_Location_ID(), null); // line = new MInvoiceLine(_invoice); // line.SetIsDescription(true); // line.SetDescription(addr.ToString()); // line.SetLine(_line + sLine.GetLine() - 1); // if (!line.Save()) // { // throw new Exception("Could not create Invoice Comment Line 2 (sh)"); // } // } //} #endregion // MInvoiceLine line1 = new MInvoiceLine(_invoice); line1.SetShipLine(sLine); line1.SetQtyEntered(sLine.GetQtyEntered()); line1.SetQtyInvoiced(sLine.GetMovementQty()); line1.SetLine(_line + sLine.GetLine()); line1.SetM_AttributeSetInstance_ID(sLine.GetM_AttributeSetInstance_ID()); if (sLine.GetA_Asset_ID() > 0) { line1.SetA_Asset_ID(sLine.GetA_Asset_ID()); if (line1.Get_ColumnIndex("VAFAM_AssetCost") > 0) { int PAcctSchema_ID = 0; int pCurrency_ID = 0; MAcctSchema as1 = MClient.Get(GetCtx(), GetAD_Client_ID()).GetAcctSchema(); if (as1 != null) { PAcctSchema_ID = as1.GetC_AcctSchema_ID(); pCurrency_ID = as1.GetC_Currency_ID(); } decimal LineNetAmt = Decimal.Multiply(line1.GetPriceActual(), line1.GetQtyEntered()); decimal AssetCost = GetAssetCost(sLine.GetA_Asset_ID(), sLine.GetM_Product_ID(), PAcctSchema_ID); AssetCost = Decimal.Multiply(AssetCost, line1.GetQtyEntered()); if (LineNetAmt > 0) { LineNetAmt = MConversionRate.Convert(GetCtx(), LineNetAmt, _invoice.GetC_Currency_ID(), pCurrency_ID, _invoice.GetAD_Client_ID(), _invoice.GetAD_Org_ID()); } decimal Diff = LineNetAmt - AssetCost; line1.Set_Value("VAFAM_AssetCost", AssetCost); line1.Set_Value("VAFAM_Difference", Diff); } } if (Env.IsModuleInstalled("VA077_")) { //invoice line line1.Set_Value("VA077_CNAutodesk", sLine.Get_Value("VA077_CNAutodesk")); line1.Set_Value("VA077_Duration", sLine.Get_Value("VA077_Duration")); line1.Set_Value("VA077_MarginAmt", sLine.Get_Value("VA077_MarginAmt")); line1.Set_Value("VA077_MarginPercent", sLine.Get_Value("VA077_MarginPercent")); line1.Set_Value("VA077_OldSN", sLine.Get_Value("VA077_OldSN")); line1.Set_Value("VA077_ProductInfo", sLine.Get_Value("VA077_ProductInfo")); line1.Set_Value("VA077_PurchasePrice", sLine.Get_Value("VA077_PurchasePrice")); line1.Set_Value("VA077_RegEmail", sLine.Get_Value("VA077_RegEmail")); line1.Set_Value("VA077_SerialNo", sLine.Get_Value("VA077_SerialNo")); line1.Set_Value("VA077_UpdateFromVersn", sLine.Get_Value("VA077_UpdateFromVersn")); line1.Set_Value("VA077_UserRef_ID", sLine.Get_Value("VA077_UserRef_ID")); line1.Set_Value("VA077_EndDate", sLine.Get_Value("VA077_EndDate")); line1.Set_Value("VA077_StartDate", sLine.Get_Value("VA077_StartDate")); } if (!line1.Save()) { ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Could not create Invoice Line (s). " + pp.GetName()); } throw new Exception("Could not create Invoice Line (s)"); } // Link sLine.SetIsInvoiced(true); if (!sLine.Save()) { ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Could not update Shipment Line. " + pp.GetName()); } throw new Exception("Could not update Shipment Line"); } log.Fine(line1.ToString()); }
/// <summary> /// Apply Payment Term with schedule to order /// </summary> /// <param name="order">Order</param> /// <param name="_sch">Payment Term Schedule</param> private void ApplyAdvanceSchedule(MOrder order, MPaySchedule _sch) { MVA009OrderPaySchedule ips = null; Decimal remainder = order.GetGrandTotal(); #region IsAdvance true on Schedule if (_sch.IsVA009_Advance()) { ips = new MVA009OrderPaySchedule(order, _sch); ips.SetVA009_ExecutionStatus("A"); MOrder _Order = new MOrder(GetCtx(), order.GetC_Order_ID(), Get_TrxName()); ips.SetVA009_PaymentMethod_ID(order.GetVA009_PaymentMethod_ID()); ips.SetC_PaymentTerm_ID(order.GetC_PaymentTerm_ID()); ips.SetVA009_GrandTotal(order.GetGrandTotal()); MPaymentTerm payterm = new MPaymentTerm(GetCtx(), order.GetC_PaymentTerm_ID(), Get_TrxName()); int _graceDay = payterm.GetGraceDays(); ips.SetVA009_FollowupDate(ips.GetDueDate().Value.AddDays(_graceDay)); ips.SetVA009_PlannedDueDate(ips.GetDueDate()); int BaseCurrency = GetCtx().GetContextAsInt("$C_Currency_ID"); if (BaseCurrency != order.GetC_Currency_ID()) { decimal multiplyRate = MConversionRate.GetRate(order.GetC_Currency_ID(), BaseCurrency, order.GetDateAcct(), order.GetC_ConversionType_ID(), order.GetAD_Client_ID(), order.GetAD_Org_ID()); ips.SetVA009_OpenAmnt(ips.GetDueAmt() * multiplyRate); } else { ips.SetVA009_OpenAmnt(ips.GetDueAmt()); } // Get Next Business Day if Next Business Days check box is set to true DateTime?payDueDate = null; if (payterm.IsNextBusinessDay()) { payDueDate = payterm.GetNextBusinessDate(ips.GetDueDate()); ips.SetDueDate(payDueDate); payDueDate = payterm.GetNextBusinessDate(ips.GetDiscountDate()); ips.SetDiscountDate(payDueDate); } ips.SetC_Currency_ID(order.GetC_Currency_ID()); ips.SetVA009_BseCurrncy(BaseCurrency); ips.SetVA009_OpnAmntInvce(ips.GetDueAmt()); ips.SetC_BPartner_ID(order.GetC_BPartner_ID()); string sql = "SELECT VA009_PaymentMode, VA009_PaymentType, VA009_PaymentTrigger FROM VA009_PaymentMethod WHERE VA009_PaymentMethod_ID=" + order.GetVA009_PaymentMethod_ID() + " AND IsActive = 'Y' AND AD_Client_ID = " + order.GetAD_Client_ID(); DataSet ds = new DataSet(); ds = DB.ExecuteDataset(sql); if (ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { ips.SetVA009_PaymentMode(Util.GetValueOfString(ds.Tables[0].Rows[0]["VA009_PaymentMode"])); if (!String.IsNullOrEmpty(Convert.ToString(ds.Tables[0].Rows[0]["VA009_PaymentType"]))) { ips.SetVA009_PaymentType(Util.GetValueOfString(ds.Tables[0].Rows[0]["VA009_PaymentType"])); } ips.SetVA009_PaymentTrigger(Util.GetValueOfString(ds.Tables[0].Rows[0]["VA009_PaymentTrigger"])); ips.SetVA009_ExecutionStatus("A"); } ips.SetProcessed(true); ips.Save(order.Get_TrxName()); log.Fine(ips.ToString()); remainder = Decimal.Subtract(remainder, ips.GetDueAmt()); } #endregion }
/// <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); }
/// <summary> /// Create Line /// </summary> /// <param name="order">order</param> /// <param name="orderLine">line</param> /// <param name="qty">Quantity</param> /// <param name="storages">storage info</param> /// <param name="force">force delivery</param> private void CreateLine(MOrder order, MOrderLine orderLine, Decimal qty, MStorage[] storages, bool force) { // Complete last Shipment - can have multiple shipments if (_lastC_BPartner_Location_ID != orderLine.GetC_BPartner_Location_ID()) { CompleteShipment(); } _lastC_BPartner_Location_ID = orderLine.GetC_BPartner_Location_ID(); // Create New Shipment if (_shipment == null) { _shipment = new MInOut(order, 0, _movementDate); _shipment.SetM_Warehouse_ID(orderLine.GetM_Warehouse_ID()); // sets Org too if (order.GetC_BPartner_ID() != orderLine.GetC_BPartner_ID()) { _shipment.SetC_BPartner_ID(orderLine.GetC_BPartner_ID()); } if (order.GetC_BPartner_Location_ID() != orderLine.GetC_BPartner_Location_ID()) { _shipment.SetC_BPartner_Location_ID(orderLine.GetC_BPartner_Location_ID()); } if (!_shipment.Save()) { throw new Exception("Could not create Shipment"); } } // Non Inventory Lines if (storages == null) { MInOutLine line = new MInOutLine(_shipment); line.SetOrderLine(orderLine, 0, Env.ZERO); line.SetQty(qty); // Correct UOM if (orderLine.GetQtyEntered().CompareTo(orderLine.GetQtyOrdered()) != 0) { line.SetQtyEntered(Decimal.Round(Decimal.Divide(Decimal.Multiply(qty, orderLine.GetQtyEntered()), orderLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero)); } line.SetLine(_line + orderLine.GetLine()); //Amit 27-jan-2014 if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='DTD001_'")) > 0) { line.SetDTD001_IsAttributeNo(true); } if (!line.Save()) { throw new Exception("Could not create Shipment Line"); } log.Fine(line.ToString()); return; } // Product MProduct product = orderLine.GetProduct(); bool linePerASI = false; if (product.GetM_AttributeSet_ID() != 0) { MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); linePerASI = mas.IsInstanceAttribute(); } // Inventory Lines List <MInOutLine> list = new List <MInOutLine>(); Decimal toDeliver = qty; for (int i = 0; i < storages.Length; i++) { MStorage storage = storages[i]; Decimal deliver = toDeliver; // Not enough On Hand if (deliver.CompareTo(storage.GetQtyOnHand()) > 0 && Env.Signum(storage.GetQtyOnHand()) >= 0) // positive storage { if (!force || // Adjust to OnHand Qty (i + 1 != storages.Length)) // if force don't adjust last location { deliver = storage.GetQtyOnHand(); } } if (Env.Signum(deliver) == 0) // zero deliver { continue; } int M_Locator_ID = storage.GetM_Locator_ID(); // MInOutLine line = null; if (!linePerASI) // find line with Locator { for (int n = 0; n < list.Count; n++) { MInOutLine test = (MInOutLine)list[n]; if (test.GetM_Locator_ID() == M_Locator_ID) { line = test; break; } } } if (line == null) // new line { line = new MInOutLine(_shipment); line.SetOrderLine(orderLine, M_Locator_ID, order.IsSOTrx() ? deliver : Env.ZERO); line.SetQty(deliver); list.Add(line); } else { // existing line line.SetQty(Decimal.Add(line.GetMovementQty(), deliver)); } if (orderLine.GetQtyEntered().CompareTo(orderLine.GetQtyOrdered()) != 0) { line.SetQtyEntered(Decimal.Round(Decimal.Divide(Decimal.Multiply(line.GetMovementQty(), orderLine.GetQtyEntered()), orderLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero)); } line.SetLine(_line + orderLine.GetLine()); if (linePerASI) { line.SetM_AttributeSetInstance_ID(storage.GetM_AttributeSetInstance_ID()); } //Amit 27-jan-2014 if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='DTD001_'")) > 0) { line.SetDTD001_IsAttributeNo(true); } if (!line.Save()) { throw new Exception("Could not create Shipment Line"); } log.Fine("ToDeliver=" + qty + "/" + deliver + " - " + line); toDeliver = Decimal.Subtract(toDeliver, deliver); // Temp adjustment storage.SetQtyOnHand(Decimal.Subtract(storage.GetQtyOnHand(), deliver)); // if (Env.Signum(toDeliver) == 0) { break; } } if (Env.Signum(toDeliver) != 0) { throw new Exception("Not All Delivered - Remainder=" + toDeliver); } }
/// <summary> /// Generate Shipments /// </summary> /// <param name="idr">Order Query</param> /// <returns>info</returns> private String Generate(IDataReader idr) { DataTable dt = new DataTable(); MClient client = MClient.Get(GetCtx()); try { dt.Load(idr); idr.Close(); //ResultSet dr = pstmt.executeQuery(); foreach (DataRow dr in dt.Rows)// while (dr.next ()) // Order { order = new MOrder(GetCtx(), dr, Get_TrxName()); // Credit Limit check added by Vivek on 24/08/2016 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 == "B" || creditVal == "D" || creditVal == "E" || creditVal == "F") { AddLog(Msg.GetMsg(GetCtx(), "StopShipment") + bp.GetName()); continue; } else if (creditVal == "H" || creditVal == "J" || creditVal == "K" || creditVal == "L") { if (_msg != null) { _msg.Clear(); } _msg.Append(Msg.GetMsg(GetCtx(), "WarningShipment") + bp.GetName()); //AddLog(Msg.GetMsg(GetCtx(), "WarningShipment") + bp.GetName()); } } } } else { 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 == "B" || creditVal == "D" || creditVal == "E" || creditVal == "F") { AddLog(Msg.GetMsg(GetCtx(), "StopShipment") + bp.GetName() + " " + bpl.GetName()); continue; } else if (creditVal == "H" || creditVal == "J" || creditVal == "K" || creditVal == "L") { if (_msg != null) { _msg.Clear(); } _msg.Append(Msg.GetMsg(GetCtx(), "WarningShipment") + bp.GetName() + " " + bpl.GetName()); //AddLog(Msg.GetMsg(GetCtx(), "WarningShipment") + bp.GetName() + " " + bpl.GetName()); } } } } } // Credit Limit End // New Header different Shipper, Shipment Location if (!_consolidateDocument || (_shipment != null && (_shipment.GetC_BPartner_Location_ID() != order.GetC_BPartner_Location_ID() || _shipment.GetM_Shipper_ID() != order.GetM_Shipper_ID()))) { CompleteShipment(); } log.Fine("check: " + order + " - DeliveryRule=" + order.GetDeliveryRule()); // DateTime?minGuaranteeDate = _movementDate; bool completeOrder = MOrder.DELIVERYRULE_CompleteOrder.Equals(order.GetDeliveryRule()); // OrderLine WHERE String where = " AND M_Warehouse_ID=" + _M_Warehouse_ID; if (_datePromised != null) { where += " AND (TRUNC(DatePromised,'DD')<=" + DB.TO_DATE((DateTime?)_datePromised, true) + " OR DatePromised IS NULL)"; //where += " AND (TRUNC(DatePromised,'DD')<='" + String.Format("{0:dd-MMM-yy}", _datePromised) // + "' OR DatePromised IS NULL)"; } // Exclude Auto Delivery if not Force if (!MOrder.DELIVERYRULE_Force.Equals(order.GetDeliveryRule())) { where += " AND (C_OrderLine.M_Product_ID IS NULL" + " OR EXISTS (SELECT * FROM M_Product p " + "WHERE C_OrderLine.M_Product_ID=p.M_Product_ID" + " AND IsExcludeAutoDelivery='N'))"; } // Exclude Unconfirmed if (!_isUnconfirmedInOut) { where += " AND NOT EXISTS (SELECT * FROM M_InOutLine iol" + " INNER JOIN M_InOut io ON (iol.M_InOut_ID=io.M_InOut_ID) " + "WHERE iol.C_OrderLine_ID=C_OrderLine.C_OrderLine_ID AND io.DocStatus IN ('IP','WC'))"; } // Deadlock Prevention - Order by M_Product_ID MOrderLine[] lines = order.GetLines(where, "ORDER BY C_BPartner_Location_ID, M_Product_ID"); for (int i = 0; i < lines.Length; i++) { MOrderLine line = lines[i]; // if order line is not drop ship type if (!line.IsDropShip()) { if (line.GetM_Warehouse_ID() != _M_Warehouse_ID) { continue; } log.Fine("check: " + line); Decimal onHand = Env.ZERO; Decimal toDeliver = Decimal.Subtract(line.GetQtyOrdered(), line.GetQtyDelivered()); Decimal QtyNotDelivered = Util.GetValueOfDecimal(DB.ExecuteScalar(@"SELECT SUM(MovementQty) FROM M_Inout i INNER JOIN M_InoutLine il ON i.M_Inout_ID = il.M_Inout_ID WHERE il.C_OrderLine_ID = " + line.GetC_OrderLine_ID() + @" AND il.Isactive = 'Y' AND i.docstatus NOT IN ('RE' , 'VO' , 'CL' , 'CO')", null, Get_Trx())); toDeliver -= QtyNotDelivered; MProduct product = line.GetProduct(); // Nothing to Deliver if (product != null && Env.Signum(toDeliver) == 0) { continue; } // Added by Bharat on 07 April 2017 as code already on Admpiere but deleted here. if (line.GetC_Charge_ID() != 0) { continue; } // Check / adjust for confirmations Decimal unconfirmedShippedQty = Env.ZERO; if (_isUnconfirmedInOut && product != null && Env.Signum(toDeliver) != 0) { String where2 = "EXISTS (SELECT * FROM M_InOut io WHERE io.M_InOut_ID=M_InOutLine.M_InOut_ID AND io.DocStatus IN ('IP','WC'))"; MInOutLine[] iols = MInOutLine.GetOfOrderLine(GetCtx(), line.GetC_OrderLine_ID(), where2, null); for (int j = 0; j < iols.Length; j++) { unconfirmedShippedQty = Decimal.Add(unconfirmedShippedQty, iols[j].GetMovementQty()); } String logInfo = "Unconfirmed Qty=" + unconfirmedShippedQty + " - ToDeliver=" + toDeliver + "->"; toDeliver = Decimal.Subtract(toDeliver, unconfirmedShippedQty); logInfo += toDeliver; if (Env.Signum(toDeliver) < 0) { toDeliver = Env.ZERO; logInfo += " (set to 0)"; } // Adjust On Hand onHand = Decimal.Subtract(onHand, unconfirmedShippedQty); log.Fine(logInfo); } // Comments & lines w/o product & services if ((product == null || !product.IsStocked()) && (Env.Signum(line.GetQtyOrdered()) == 0 || // comments Env.Signum(toDeliver) != 0)) // lines w/o product { if (!MOrder.DELIVERYRULE_CompleteOrder.Equals(order.GetDeliveryRule())) // printed later { CreateLine(order, line, toDeliver, null, false); } continue; } // Stored Product MProductCategory pc = MProductCategory.Get(order.GetCtx(), product.GetM_Product_Category_ID()); String MMPolicy = pc.GetMMPolicy(); if (MMPolicy == null || MMPolicy.Length == 0) { MMPolicy = client.GetMMPolicy(); } // MStorage[] storages = GetStorages(line.GetM_Warehouse_ID(), line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), product.GetM_AttributeSet_ID(), line.GetM_AttributeSetInstance_ID() == 0, (DateTime?)minGuaranteeDate, MClient.MMPOLICY_FiFo.Equals(MMPolicy)); for (int j = 0; j < storages.Length; j++) { MStorage storage = storages[j]; onHand = Decimal.Add(onHand, storage.GetQtyOnHand()); } bool fullLine = onHand.CompareTo(toDeliver) >= 0 || Env.Signum(toDeliver) < 0; // Complete Order if (completeOrder && !fullLine) { log.Fine("Failed CompleteOrder - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + " - " + line); completeOrder = false; break; } // Complete Line else if (fullLine && MOrder.DELIVERYRULE_CompleteLine.Equals(order.GetDeliveryRule())) { log.Fine("CompleteLine - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ", ToDeliver=" + toDeliver + " - " + line); // CreateLine(order, line, toDeliver, storages, false); } // Availability else if (MOrder.DELIVERYRULE_Availability.Equals(order.GetDeliveryRule()) && (Env.Signum(onHand) > 0 || Env.Signum(toDeliver) < 0)) { Decimal deliver = toDeliver; if (deliver.CompareTo(onHand) > 0) { deliver = onHand; } log.Fine("Available - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + ", Delivering=" + deliver + " - " + line); // CreateLine(order, line, deliver, storages, false); } // Force else if (MOrder.DELIVERYRULE_Force.Equals(order.GetDeliveryRule())) { Decimal deliver = toDeliver; log.Fine("Force - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + ", Delivering=" + deliver + " - " + line); // CreateLine(order, line, deliver, storages, true); } // Manual else if (MOrder.DELIVERYRULE_Manual.Equals(order.GetDeliveryRule())) { log.Fine("Manual - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ") - " + line); } else { log.Fine("Failed: " + order.GetDeliveryRule() + " - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + " - " + line); } } }// for all order lines // Complete Order successful if (completeOrder && MOrder.DELIVERYRULE_CompleteOrder.Equals(order.GetDeliveryRule())) { for (int i = 0; i < lines.Length; i++) { MOrderLine line = lines[i]; // if order line is not drop ship type if (!line.IsDropShip()) { if (line.GetM_Warehouse_ID() != _M_Warehouse_ID) { continue; } MProduct product = line.GetProduct(); Decimal toDeliver = Decimal.Subtract(line.GetQtyOrdered(), line.GetQtyDelivered()); // MStorage[] storages = null; if (product != null && product.IsStocked()) { MProductCategory pc = MProductCategory.Get(order.GetCtx(), product.GetM_Product_Category_ID()); String MMPolicy = pc.GetMMPolicy(); if (MMPolicy == null || MMPolicy.Length == 0) { MMPolicy = client.GetMMPolicy(); } // storages = GetStorages(line.GetM_Warehouse_ID(), line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), product.GetM_AttributeSet_ID(), line.GetM_AttributeSetInstance_ID() == 0, (DateTime?)minGuaranteeDate, MClient.MMPOLICY_FiFo.Equals(MMPolicy)); } // CreateLine(order, line, toDeliver, storages, false); } } } _line += 1000; } // while order } catch (Exception e) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, _sql, e); } finally { if (idr != null) { idr.Close(); } dt = null; } CompleteShipment(); return("@Created@ = " + _created); }
/// <summary> /// Create Shipment /// </summary> /// <returns>info</returns> protected override String DoIt() { //log.info("C_Invoice_ID=" + _C_Invoice_ID // + ", M_Warehouse_ID=" + _M_Warehouse_ID // + ", C_DocType_ID=" + _C_DocType_ID); if (_C_Invoice_ID == 0) { throw new ArgumentException("@NotFound@ @C_Invoice_ID@"); } if (_M_Warehouse_ID == 0) { throw new ArgumentException("@NotFound@ @M_Warehouse_ID@"); } // MInvoice invoice = new MInvoice(GetCtx(), _C_Invoice_ID, Get_Trx()); if (invoice.Get_ID() == 0) { throw new ArgumentException("@NotFound@ @C_Invoice_ID@"); } if (!MInvoice.DOCSTATUS_Completed.Equals(invoice.GetDocStatus())) { throw new ArgumentException("@InvoiceCreateDocNotCompleted@"); } MDocType dt = MDocType.Get(GetCtx(), _C_DocType_ID); if (invoice.IsSOTrx() != dt.IsSOTrx() || invoice.IsReturnTrx() != dt.IsReturnTrx()) { throw new ArgumentException("@C_DocType_ID@ <> @C_Invoice_ID@"); } //*****************************Vikas 1 Dec 2015 ********************************* //Case Msg Not Showing Proper MInOut ship = null; MOrder ord = new MOrder(GetCtx(), invoice.GetC_Order_ID(), null); if (ord.GetC_BPartner_ID() > 0) { ship = new MInOut(invoice, _C_DocType_ID, null, _M_Warehouse_ID); // Change by Mohit Asked by Amardeep sir 02/03/2016 ship.SetPOReference(invoice.GetPOReference()); // End if (!ship.Save()) { return(GetRetrievedError(ship, "@SaveError@ Receipt")); // throw new ArgumentException("@SaveError@ Receipt"); } } else { return(GetRetrievedError(ship, "InvoiceNotLinkedWithPO")); //throw new ArgumentException("@InvoiceNotLinkedWithPO@"); } /* * MInOut ship = new MInOut(invoice, _C_DocType_ID, null, _M_Warehouse_ID); * if (!ship.Save()) * { * throw new ArgumentException("@SaveError@ Receipt"); * } */ //************************END***************************************** MInvoiceLine[] invoiceLines = invoice.GetLines(false); for (int i = 0; i < invoiceLines.Length; i++) { MInvoiceLine invoiceLine = invoiceLines[i]; MProduct product = invoiceLine.GetProduct(); // Nothing to Deliver // Get the lines of Invoice based on the setting taken on Tenant to allow non item Product if (Util.GetValueOfString(GetCtx().GetContext("$AllowNonItem")).Equals("N") && ((product != null && product.GetProductType() != MProduct.PRODUCTTYPE_Item) || invoiceLine.GetC_Charge_ID() != 0)) { continue; } MInOutLine sLine = new MInOutLine(ship); //JID_1679 Generate Receipt from Invoice(Vendor) for remaining quantity //decimal movementqty = 0; //if (invoiceLine.GetC_OrderLine_ID() != 0) //{ // decimal? res = 0; // movementqty = Util.GetValueOfDecimal(DB.ExecuteScalar(@" select (QtyOrdered-sum(MovementQty)) from C_OrderLine ol Inner join M_InOutLine il on il.C_orderline_ID= ol.C_Orderline_Id " // + " WHERE il.C_OrderLine_ID =" + invoiceLine.GetC_OrderLine_ID() + "group by QtyOrdered", null, Get_Trx())); // // in case of partial receipt // if (invoiceLine.GetQtyInvoiced() > movementqty && movementqty != 0) // { // if (product.GetC_UOM_ID() != invoiceLine.GetC_UOM_ID()) // { // res = MUOMConversion.ConvertProductTo(GetCtx(), product.GetM_Product_ID(), invoiceLine.GetC_UOM_ID(), movementqty); // } // sLine.SetInvoiceLine(invoiceLine, 0, // Locator // invoice.IsSOTrx() ? (movementqty) : Env.ZERO); // sLine.SetQtyEntered(res == 0 ? (movementqty) : res); // sLine.SetMovementQty(movementqty); // } // // if QtyInvoiced is less or No Material receipt is found against the order // else // { // sLine.SetInvoiceLine(invoiceLine, 0, // Locator // invoice.IsSOTrx() ? invoiceLine.GetQtyInvoiced() : Env.ZERO); // sLine.SetQtyEntered(invoiceLine.GetQtyEntered()); // sLine.SetMovementQty(invoiceLine.GetQtyInvoiced()); // } //} //else //{ sLine.SetInvoiceLine(invoiceLine, 0, // Locator invoice.IsSOTrx() ? invoiceLine.GetQtyInvoiced() : Env.ZERO); sLine.SetQtyEntered(invoiceLine.GetQtyEntered()); sLine.SetMovementQty(invoiceLine.GetQtyInvoiced()); //} if (invoice.IsCreditMemo()) { sLine.SetQtyEntered(Decimal.Negate(sLine.GetQtyEntered())); //.negate()); sLine.SetMovementQty(Decimal.Negate(sLine.GetMovementQty())); //.negate()); } if (!sLine.Save()) { ship.Get_Trx().Rollback(); //if (movementqty == 0) //{ // _processMsg += ", LineNo: " + invoiceLine.GetLine() + Msg.GetMsg(GetCtx(), "MRIsAlreadyCreated"); // return _processMsg; //} //else //{ return(GetRetrievedError(sLine, "@SaveError@ @M_InOutLine_ID@")); //} // throw new ArgumentException("@SaveError@ @M_InOutLine_ID@"); } invoiceLine.SetM_InOutLine_ID(sLine.GetM_InOutLine_ID()); // _processMsg+= ", LineNo: "+invoiceLine.GetLine()+Msg.GetMsg(GetCtx(), "MRCreatedWithDocNo" + ship.GetDocumentNo()); if (!invoiceLine.Save()) { return(GetRetrievedError(invoiceLine, "@SaveError@ @C_InvoiceLine_ID@")); //throw new ArgumentException("@SaveError@ @C_InvoiceLine_ID@"); } } return(ship.GetDocumentNo()); }
/// <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"); } }
/// <summary> /// Perform Process. /// </summary> /// <returns>Message (clear text)</returns> protected override String DoIt() { //log.Info("C_Order_ID=" + _C_Order_ID // + ", C_DocType_ID=" + _C_DocType_ID // + ", CloseDocument=" + _IsCloseDocument); //if (_C_Order_ID == 0) //{ // throw new ArgumentException("No Order"); //} //MDocType dt = MDocType.Get(GetCtx(), _C_DocType_ID); //if (dt.Get_ID() == 0) //{ // throw new ArgumentException("No DocType"); //} //if (_DateDoc == null) //{ // _DateDoc = DateTime.Now; // //Util.GetValueOfDateTime(new DateTime(CommonFunctions.CurrentTimeMillis())); //} //// //MOrder from = new MOrder(GetCtx(), _C_Order_ID, Get_Trx()); //MOrder newOrder = MOrder.CopyFrom(from, _DateDoc, // dt.GetC_DocType_ID(), false, true, null); // copy ASI //newOrder.SetC_DocTypeTarget_ID(_C_DocType_ID); //bool OK = newOrder.Save (); //if (!OK) //{ // throw new Exception("Could not create new Order"); //} //// //if (_IsCloseDocument) //{ // MOrder original = new MOrder(GetCtx(), _C_Order_ID, Get_Trx()); // original.SetDocAction(MOrder.DOCACTION_Complete); // original.ProcessIt(MOrder.DOCACTION_Complete); // original.Save(); // original.SetDocAction(MOrder.DOCACTION_Close); // original.ProcessIt(MOrder.DOCACTION_Close); // original.Save(); //} //// //return dt.GetName() + ": " + newOrder.GetDocumentNo(); log.Info("C_Order_ID=" + _C_Order_ID + ", C_DocType_ID=" + _C_DocType_ID + ", CloseDocument=" + _IsCloseDocument); if (_C_Order_ID == 0) { throw new ArgumentException("No Order"); } VAdvantage.Model.MDocType dt = VAdvantage.Model.MDocType.Get(GetCtx(), _C_DocType_ID); if (dt.Get_ID() == 0) { throw new ArgumentException("No DocType"); } if (_DateDoc == null) { _DateDoc = Util.GetValueOfDateTime(DateTime.Now); } // VAdvantage.Model.MOrder from = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx()); MOrder newOrder = MOrder.CopyFrom(from, _DateDoc, dt.GetC_DocType_ID(), false, true, null, true);//Pass optional parameter as True that we are going to create Order from Create Sales Order Process on Sales Quotation window---Neha newOrder.SetC_DocTypeTarget_ID(_C_DocType_ID); //Update New Order Refrence From Sales Qutation in Sales order newOrder.SetPOReference(Util.GetValueOfString(from.GetDocumentNo())); int C_Bpartner_ID = newOrder.GetC_BPartner_ID(); newOrder.Set_Value("IsSalesQuotation", false); // Added by Bharat on 31 Jan 2018 to set Inco Term from Quotation if (newOrder.Get_ColumnIndex("C_IncoTerm_ID") > 0) { newOrder.SetC_IncoTerm_ID(from.GetC_IncoTerm_ID()); } String sqlbp = "update c_project set c_bpartner_id=" + C_Bpartner_ID + " where ref_order_id=" + _C_Order_ID + ""; int value = DB.ExecuteQuery(sqlbp, null, Get_Trx()); bool OK = newOrder.Save(); if (!OK) { throw new Exception("Could not create new Order"); } if (OK) { string sql = "select C_Project_id from c_project where c_order_id = " + from.GetC_Order_ID(); int C_Project_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())); if (C_Project_ID != 0) { VAdvantage.Model.X_C_Project project = new VAdvantage.Model.X_C_Project(GetCtx(), C_Project_ID, Get_Trx()); project.SetC_BPartner_ID(project.GetC_BPartnerSR_ID()); project.SetC_BPartnerSR_ID(0); if (!project.Save()) { } } from.SetRef_Order_ID(newOrder.GetC_Order_ID()); from.Save(); int bp = newOrder.GetC_BPartner_ID(); VAdvantage.Model.X_C_BPartner prosp = new VAdvantage.Model.X_C_BPartner(GetCtx(), bp, Get_Trx()); prosp.SetIsCustomer(true); prosp.SetIsProspect(false); prosp.Save(); } // if (_IsCloseDocument) { VAdvantage.Model.MOrder original = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx()); //Edited by Arpit Rai on 8th of Nov,2017 if (original.GetDocStatus() != "CO") //to check if document is already completed { original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Complete); original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Complete); original.Save(); } //Arpit original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Close); original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Close); original.Save(); } // return(Msg.GetMsg(GetCtx(), "OrderCreatedSuccessfully") + " - " + dt.GetName() + ": " + newOrder.GetDocumentNo()); }
/** * Create PO from Planned Amt/Qty * @param projectLine project line */ private void CreatePO(MProject project, MProjectLine projectLine) { if (projectLine.GetM_Product_ID() == 0) { AddLog(projectLine.GetLine(), null, null, "Line has no Product"); return; } if (projectLine.GetC_OrderPO_ID() != 0) { AddLog(projectLine.GetLine(), null, null, "Line was ordered previously"); return; } // PO Record MProductPO[] pos = MProductPO.GetOfProduct(GetCtx(), projectLine.GetM_Product_ID(), Get_TrxName()); if (pos == null || pos.Length == 0) { AddLog(projectLine.GetLine(), null, null, "Product has no PO record"); return; } // Create to Order MOrder order = null; // try to find PO to C_BPartner for (int i = 0; i < m_pos.Count; i++) { MOrder test = m_pos[i]; if (test.GetC_BPartner_ID() == pos[0].GetC_BPartner_ID()) { order = test; break; } } if (order == null) // create new Order { // Vendor MBPartner bp = new MBPartner(GetCtx(), pos[0].GetC_BPartner_ID(), Get_TrxName()); // New Order order = new MOrder(project, false, null); int AD_Org_ID = projectLine.GetAD_Org_ID(); if (AD_Org_ID == 0) { log.Warning("createPOfromProjectLine - AD_Org_ID=0"); AD_Org_ID = GetCtx().GetAD_Org_ID(); if (AD_Org_ID != 0) { projectLine.SetAD_Org_ID(AD_Org_ID); } } order.SetClientOrg(projectLine.GetAD_Client_ID(), AD_Org_ID); order.SetBPartner(bp); order.SetC_Project_ID(project.Get_ID()); order.Save(); // optionally save for consolidation if (m_ConsolidateDocument) { m_pos.Add(order); } } // Create Line MOrderLine orderLine = new MOrderLine(order); orderLine.SetM_Product_ID(projectLine.GetM_Product_ID(), true); orderLine.SetQty(projectLine.GetPlannedQty()); orderLine.SetDescription(projectLine.GetDescription()); // (Vendor) PriceList Price orderLine.SetPrice(); if (Env.Signum(orderLine.GetPriceActual()) == 0) { // Try to find purchase price Decimal poPrice = pos[0].GetPricePO(); int C_Currency_ID = pos[0].GetC_Currency_ID(); // if (Env.Signum(poPrice) == 0) { poPrice = pos[0].GetPriceLastPO(); } if (Env.Signum(poPrice) == 0) { poPrice = pos[0].GetPriceList(); } // We have a price if (Env.Signum(poPrice) != 0) { if (order.GetC_Currency_ID() != C_Currency_ID) { poPrice = VAdvantage.Model.MConversionRate.Convert(GetCtx(), poPrice, C_Currency_ID, order.GetC_Currency_ID(), order.GetDateAcct(), order.GetC_ConversionType_ID(), order.GetAD_Client_ID(), order.GetAD_Org_ID()); } orderLine.SetPrice(poPrice); } } orderLine.SetTax(); orderLine.Save(); // touch order to recalculate tax and totals order.SetIsActive(order.IsActive()); order.Save(); // update ProjectLine projectLine.SetC_OrderPO_ID(order.GetC_Order_ID()); projectLine.Save(); AddLog(projectLine.GetLine(), null, projectLine.GetPlannedQty(), order.GetDocumentNo()); }
/** * 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()); // Credit Limit check added by Vivek on 24/08/2016 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()); } } } } else { 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 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(); 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; } // CreateLine(order, shipment, shipLine); } // shipment lines 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); } // if (oLine.IsContract() == false) { 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; // 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); }
/// <summary> /// Create Shipment /// </summary> /// <returns>info</returns> protected override String DoIt() { //log.info("C_Invoice_ID=" + _C_Invoice_ID // + ", M_Warehouse_ID=" + _M_Warehouse_ID // + ", C_DocType_ID=" + _C_DocType_ID); if (_C_Invoice_ID == 0) { throw new ArgumentException("@NotFound@ @C_Invoice_ID@"); } if (_M_Warehouse_ID == 0) { throw new ArgumentException("@NotFound@ @M_Warehouse_ID@"); } // MInvoice invoice = new MInvoice(GetCtx(), _C_Invoice_ID, null); if (invoice.Get_ID() == 0) { throw new ArgumentException("@NotFound@ @C_Invoice_ID@"); } if (!MInvoice.DOCSTATUS_Completed.Equals(invoice.GetDocStatus())) { throw new ArgumentException("@InvoiceCreateDocNotCompleted@"); } MDocType dt = MDocType.Get(GetCtx(), _C_DocType_ID); if (invoice.IsSOTrx() != dt.IsSOTrx() || invoice.IsReturnTrx() != dt.IsReturnTrx()) { throw new ArgumentException("@C_DocType_ID@ <> @C_Invoice_ID@"); } //*****************************Vikas 1 Dec 2015 ********************************* //Case Msg Not Showing Proper MInOut ship = null; MOrder ord = new MOrder(GetCtx(), invoice.GetC_Order_ID(), null); if (ord.GetC_BPartner_ID() > 0) { ship = new MInOut(invoice, _C_DocType_ID, null, _M_Warehouse_ID); if (!ship.Save()) { throw new ArgumentException("@SaveError@ Receipt"); } } else { throw new ArgumentException("@InvoiceNotLinkedWithPO@"); } /* * MInOut ship = new MInOut(invoice, _C_DocType_ID, null, _M_Warehouse_ID); * if (!ship.Save()) * { * throw new ArgumentException("@SaveError@ Receipt"); * } */ //************************END***************************************** MInvoiceLine[] invoiceLines = invoice.GetLines(false); for (int i = 0; i < invoiceLines.Length; i++) { MInvoiceLine invoiceLine = invoiceLines[i]; MInOutLine sLine = new MInOutLine(ship); sLine.SetInvoiceLine(invoiceLine, 0, // Locator invoice.IsSOTrx() ? invoiceLine.GetQtyInvoiced() : Env.ZERO); sLine.SetQtyEntered(invoiceLine.GetQtyEntered()); sLine.SetMovementQty(invoiceLine.GetQtyInvoiced()); if (invoice.IsCreditMemo()) { sLine.SetQtyEntered(Decimal.Negate(sLine.GetQtyEntered())); //.negate()); sLine.SetMovementQty(Decimal.Negate(sLine.GetMovementQty())); //.negate()); } if (!sLine.Save()) { throw new ArgumentException("@SaveError@ @M_InOutLine_ID@"); } // invoiceLine.SetM_InOutLine_ID(sLine.GetM_InOutLine_ID()); if (!invoiceLine.Save()) { throw new ArgumentException("@SaveError@ @C_InvoiceLine_ID@"); } } return(ship.GetDocumentNo()); }
/// <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 (!_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 (!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()); }
/** * Apply Payment Term without schedule to Order * @param Order Order * @return false as no payment schedule */ private bool ApplyNoOrderSchedule(MOrder Order) { DeleteOrderPaySchedule(Order.GetC_Order_ID(), Order.Get_TrxName()); // updateOrder if (Order.GetC_PaymentTerm_ID() != GetC_PaymentTerm_ID()) { Order.SetC_PaymentTerm_ID(GetC_PaymentTerm_ID()); } //if (Order.IsPayScheduleValid()) // Order.SetIsPayScheduleValid(false); //----------------Anuj------11/09/2015------------------------ int _CountVA009 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA009_' AND IsActive = 'Y'")); if (_CountVA009 > 0) { StringBuilder _sql = new StringBuilder(); //MOrderPaySchedule schedule = new MOrderPaySchedule(GetCtx(), 0, Get_TrxName()); MPaymentTerm payterm = new MPaymentTerm(GetCtx(), Order.GetC_PaymentTerm_ID(), Get_TrxName()); schedule.SetAD_Client_ID(Order.GetAD_Client_ID()); schedule.SetAD_Org_ID(Order.GetAD_Org_ID()); schedule.SetC_Order_ID(Order.GetC_Order_ID()); schedule.SetC_DocType_ID(Order.GetC_DocType_ID()); schedule.SetC_PaymentTerm_ID(Order.GetC_PaymentTerm_ID()); schedule.SetVA009_GrandTotal(Order.GetGrandTotal()); schedule.SetVA009_PaymentMethod_ID(Order.GetVA009_PaymentMethod_ID()); schedule.SetDueDate(GetDueDate(Order)); schedule.SetDueAmt(Order.GetGrandTotal()); schedule.SetDiscountDate(Order.GetDateOrderd().Value.AddDays(Util.GetValueOfInt(payterm.GetDiscountDays()))); schedule.SetDiscountAmt((Util.GetValueOfDecimal((Order.GetGrandTotal() * payterm.GetDiscount()) / 100))); schedule.SetDiscountDays2(Order.GetDateOrderd().Value.AddDays(Util.GetValueOfInt(payterm.GetDiscountDays2()))); schedule.SetDiscount2((Util.GetValueOfDecimal((Order.GetGrandTotal() * payterm.GetDiscount2()) / 100))); schedule.SetVA009_PlannedDueDate(GetDueDate(Order)); _sql.Clear(); _sql.Append(@"SELECT UNIQUE asch.C_Currency_ID FROM c_acctschema asch INNER JOIN ad_clientinfo ci ON ci.c_acctschema1_id = asch.c_acctschema_id INNER JOIN ad_client c ON c.ad_client_id = ci.ad_client_id INNER JOIN c_Order i ON c.ad_client_id = i.ad_client_id WHERE i.ad_client_id = " + Order.GetAD_Client_ID()); int BaseCurrency = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString(), null, null)); if (BaseCurrency != Order.GetC_Currency_ID()) { // change by amit _sql.Clear(); _sql.Append(@"SELECT multiplyrate FROM c_conversion_rate WHERE AD_Client_ID = " + GetCtx().GetAD_Client_ID() + " AND c_currency_id = " + Order.GetC_Currency_ID() + " AND c_currency_to_id = " + BaseCurrency + " AND " + GlobalVariable.TO_DATE(Order.GetDateAcct(), true) + " BETWEEN ValidFrom AND ValidTo"); decimal multiplyRate = Util.GetValueOfDecimal(DB.ExecuteScalar(_sql.ToString(), null, null)); if (multiplyRate == 0) { _sql.Clear(); _sql.Append(@"SELECT dividerate FROM c_conversion_rate WHERE AD_Client_ID = " + GetCtx().GetAD_Client_ID() + " AND c_currency_id = " + BaseCurrency + " AND c_currency_to_id = " + Order.GetC_Currency_ID() + " AND " + GlobalVariable.TO_DATE(Order.GetDateAcct(), true) + " BETWEEN ValidFrom AND ValidTo"); multiplyRate = Util.GetValueOfDecimal(DB.ExecuteScalar(_sql.ToString(), null, null)); } schedule.SetVA009_OpenAmnt(Order.GetGrandTotal() * multiplyRate); } else { schedule.SetVA009_OpenAmnt(Order.GetGrandTotal()); } schedule.SetC_Currency_ID(Order.GetC_Currency_ID()); schedule.SetVA009_BseCurrncy(BaseCurrency); schedule.SetVA009_OpnAmntInvce(Order.GetGrandTotal()); schedule.SetC_BPartner_ID(Order.GetC_BPartner_ID()); MOrder _Order = new MOrder(GetCtx(), Order.GetC_Order_ID(), Get_TrxName()); //schedule.SetVA009_PaymentMethod_ID(_Order.GetVA009_PaymentMethod_ID()); //schedule.SetC_PaymentTerm_ID(_Order.GetC_PaymentTerm_ID()); int _graceDay = payterm.GetGraceDays(); DateTime?_followUpDay = GetDueDate(Order); schedule.SetVA009_FollowupDate(_followUpDay.Value.AddDays(_graceDay)); _sql.Clear(); _sql.Append("Select va009_paymentmode, va009_paymenttype, va009_paymenttrigger From va009_paymentmethod where va009_paymentmethod_ID=" + Order.GetVA009_PaymentMethod_ID() + " AND IsActive = 'Y' AND AD_Client_ID = " + Order.GetAD_Client_ID()); DataSet ds = new DataSet(); ds = DB.ExecuteDataset(_sql.ToString()); if (ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { schedule.SetVA009_PaymentMode(Util.GetValueOfString(ds.Tables[0].Rows[i]["va009_paymentmode"])); schedule.SetVA009_PaymentType(Util.GetValueOfString(ds.Tables[0].Rows[i]["va009_paymenttype"])); schedule.SetVA009_PaymentTrigger(Util.GetValueOfString(ds.Tables[0].Rows[i]["va009_paymenttrigger"])); schedule.SetVA009_ExecutionStatus("A"); } } if (!schedule.Save()) { return(false); } return(true); } else { return(false); } }
/// <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); }
/** * Apply Payment Term with schedule to Order * @param Order Order * @return true if payment schedule is valid */ private bool ApplyOrderSchedule(MOrder Order) { DeleteOrderPaySchedule(Order.GetC_Order_ID(), Order.Get_TrxName()); // Create Schedule MOrderPaySchedule ips = null; Decimal remainder = Order.GetGrandTotal(); for (int i = 0; i < _schedule.Length; i++) { ips = new MOrderPaySchedule(Order, _schedule[i]); //int _CountVA009 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA009_' AND IsActive = 'Y'")); //if (_CountVA009 > 0) //{ // ips.SetVA009_ExecutionStatus("A"); // ips.SetC_DocType_ID(Order.GetC_DocType_ID()); //} int _CountVA009 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA009_' AND IsActive = 'Y'")); if (_CountVA009 > 0) { ips.SetVA009_ExecutionStatus("A"); ips.SetC_DocType_ID(Order.GetC_DocType_ID()); MOrder _Order = new MOrder(GetCtx(), Order.GetC_Order_ID(), Get_TrxName()); ips.SetVA009_PaymentMethod_ID(Order.GetVA009_PaymentMethod_ID()); ips.SetC_PaymentTerm_ID(Order.GetC_PaymentTerm_ID()); ips.SetVA009_GrandTotal(Order.GetGrandTotal()); MPaymentTerm payterm = new MPaymentTerm(GetCtx(), Order.GetC_PaymentTerm_ID(), Get_TrxName()); int _graceDay = payterm.GetGraceDays(); //DateTime? _followUpDay = GetDueDate(Order); ips.SetVA009_FollowupDate(ips.GetDueDate().Value.AddDays(_graceDay)); //ips.SetVA009_PlannedDueDate(GetDueDate(Order)); ips.SetVA009_PlannedDueDate(ips.GetDueDate()); //ips.SetDueDate(GetDueDate(Order)); //change by amit 25-11-2015 StringBuilder _sql = new StringBuilder(); _sql.Clear(); _sql.Append(@"SELECT UNIQUE asch.C_Currency_ID FROM c_acctschema asch INNER JOIN ad_clientinfo ci ON ci.c_acctschema1_id = asch.c_acctschema_id INNER JOIN ad_client c ON c.ad_client_id = ci.ad_client_id INNER JOIN c_Order i ON c.ad_client_id = i.ad_client_id WHERE i.ad_client_id = " + Order.GetAD_Client_ID()); int BaseCurrency = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString(), null, null)); if (BaseCurrency != Order.GetC_Currency_ID()) { _sql.Clear(); _sql.Append(@"SELECT multiplyrate FROM c_conversion_rate WHERE AD_Client_ID = " + Order.GetAD_Client_ID() + " AND c_currency_id = " + Order.GetC_Currency_ID() + " AND c_currency_to_id = " + BaseCurrency + " AND " + GlobalVariable.TO_DATE(Order.GetDateAcct(), true) + " BETWEEN ValidFrom AND ValidTo"); decimal multiplyRate = Util.GetValueOfDecimal(DB.ExecuteScalar(_sql.ToString(), null, null)); if (multiplyRate == 0) { _sql.Clear(); _sql.Append(@"SELECT dividerate FROM c_conversion_rate WHERE AD_Client_ID = " + Order.GetAD_Client_ID() + " AND c_currency_id = " + BaseCurrency + " AND c_currency_to_id = " + Order.GetC_Currency_ID() + " AND " + GlobalVariable.TO_DATE(Order.GetDateAcct(), true) + " BETWEEN ValidFrom AND ValidTo"); multiplyRate = Util.GetValueOfDecimal(DB.ExecuteScalar(_sql.ToString(), null, null)); } ips.SetVA009_OpenAmnt(ips.GetDueAmt() * multiplyRate); } else { ips.SetVA009_OpenAmnt(ips.GetDueAmt()); } ips.SetC_Currency_ID(Order.GetC_Currency_ID()); ips.SetVA009_BseCurrncy(BaseCurrency); ips.SetVA009_OpnAmntInvce(ips.GetDueAmt()); ips.SetC_BPartner_ID(Order.GetC_BPartner_ID()); //end string sql = "Select va009_paymentmode, va009_paymenttype, va009_paymenttrigger From va009_paymentmethod where va009_paymentmethod_ID=" + Order.GetVA009_PaymentMethod_ID() + " AND IsActive = 'Y' AND AD_Client_ID = " + Order.GetAD_Client_ID(); DataSet ds = new DataSet(); ds = DB.ExecuteDataset(sql); if (ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { for (int j = 0; j < ds.Tables[0].Rows.Count; j++) { ips.SetVA009_PaymentMode(Util.GetValueOfString(ds.Tables[0].Rows[j]["va009_paymentmode"])); ips.SetVA009_PaymentType(Util.GetValueOfString(ds.Tables[0].Rows[j]["va009_paymenttype"])); ips.SetVA009_PaymentTrigger(Util.GetValueOfString(ds.Tables[0].Rows[j]["va009_paymenttrigger"])); ips.SetVA009_ExecutionStatus("A"); } } } ips.Save(Order.Get_TrxName()); log.Fine(ips.ToString()); remainder = Decimal.Subtract(remainder, ips.GetDueAmt()); } // for all schedules // Remainder - update last if (remainder.CompareTo(Env.ZERO) != 0 && ips != null) { ips.SetDueAmt(Decimal.Add(ips.GetDueAmt(), remainder)); ips.Save(Order.Get_TrxName()); log.Fine("Remainder=" + remainder + " - " + ips); } // updateOrder if (Order.GetC_PaymentTerm_ID() != GetC_PaymentTerm_ID()) { Order.SetC_PaymentTerm_ID(GetC_PaymentTerm_ID()); } return(Order.ValidatePaySchedule()); }
/// <summary> /// Create PO for Vendor /// </summary> /// <param name="C_BPartner_ID">vendor</param> /// <param name="so">sales order</param> /// <returns>MOrder</returns> public MOrder CreatePOForVendor(int C_BPartner_ID, MOrder so, string _shipDrop) { MOrder po = new MOrder(GetCtx(), 0, Get_TrxName()); po.SetClientOrg(so.GetAD_Client_ID(), so.GetAD_Org_ID()); po.SetRef_Order_ID(so.GetC_Order_ID()); po.SetIsSOTrx(false); // method edited to set unreleased document type for PO po.SetC_DocTypeTarget_ID(false); // po.SetDescription(so.GetDescription()); po.SetPOReference(so.GetDocumentNo()); po.SetPriorityRule(so.GetPriorityRule()); po.SetSalesRep_ID(so.GetSalesRep_ID()); // Code Commented by Vivek Kumar on 20/09/2017 Assigned By Pradeep for drop shipment //po.SetM_Warehouse_ID(so.GetM_Warehouse_ID()); // Set Vendor MBPartner vendor = new MBPartner(GetCtx(), C_BPartner_ID, Get_TrxName()); if (Env.IsModuleInstalled("VA009_")) { // Set PO Payment Method from Vendor if (Util.GetValueOfInt(vendor.GetVA009_PO_PaymentMethod_ID()) > 0) { po.SetVA009_PaymentMethod_ID(Util.GetValueOfInt(vendor.GetVA009_PO_PaymentMethod_ID())); } else { if (string.IsNullOrEmpty(messageErrorOrSetting.ToString())) { messageErrorOrSetting.Append(Msg.GetMsg(GetCtx(), "VIS_PaymentMethodNotDefined") + " : " + vendor.GetName()); } else { messageErrorOrSetting.Append(" , " + Msg.GetMsg(GetCtx(), "VIS_PaymentMethodNotDefined") + " : " + vendor.GetName()); } po = null; return(po); } } //JID_1252: If Vendor do not have Po Pricelist bind. System should give message. if (vendor.GetPO_PriceList_ID() > 0) { po.SetM_PriceList_ID(vendor.GetPO_PriceList_ID()); } else { if (string.IsNullOrEmpty(messageErrorOrSetting.ToString())) { messageErrorOrSetting.Append(Msg.GetMsg(GetCtx(), "VIS_VendorPrcListNotDefine") + " : " + vendor.GetName()); } else { messageErrorOrSetting.Append(" , " + Msg.GetMsg(GetCtx(), "VIS_VendorPrcListNotDefine") + " : " + vendor.GetName()); } po = null; return(po); } // JID_1262: If Payment Term is not bind BP, BP Group and No Default Payment Term. System do not create PO neither give message. if (vendor.GetPO_PaymentTerm_ID() > 0) { po.SetC_PaymentTerm_ID(vendor.GetPO_PaymentTerm_ID()); } else { if (string.IsNullOrEmpty(messageErrorOrSetting.ToString())) { messageErrorOrSetting.Append(Msg.GetMsg(GetCtx(), "VIS_VendorPaytemNotDefine") + " : " + vendor.GetName()); } else { messageErrorOrSetting.Append(" , " + Msg.GetMsg(GetCtx(), "VIS_VendorPaytemNotDefine") + " : " + vendor.GetName()); } po = null; return(po); } po.SetBPartner(vendor); // Code Commented by Vivek Kumar on 20/09/2017 Assigned By Pradeep for drop shipment // Drop Ship //po.SetIsDropShip(so.IsDropShip()); //if (so.IsDropShip()) //{ // po.SetShip_BPartner_ID(so.GetC_BPartner_ID()); // po.SetShip_Location_ID(so.GetC_BPartner_Location_ID()); // po.SetShip_User_ID(so.GetAD_User_ID()); //} if (_shipDrop == "Y") { po.SetIsDropShip(true); po.SetShipToPartner_ID(so.GetC_BPartner_ID()); po.SetShipToLocation_ID(so.GetC_BPartner_Location_ID()); int _Warehouse_ID = Util.GetValueOfInt(DB.ExecuteScalar("Select M_WareHouse_ID From M_Warehouse Where AD_Org_ID=" + so.GetAD_Org_ID() + " AND Isdropship='Y' AND IsActive='Y'")); if (_Warehouse_ID >= 0) { po.SetM_Warehouse_ID(_Warehouse_ID); } } // Added by Bharat on 29 Jan 2018 to set Inco Term from Order if (po.Get_ColumnIndex("C_IncoTerm_ID") > 0) { po.SetC_IncoTerm_ID(so.GetC_IncoTerm_ID()); } // References po.SetC_Activity_ID(so.GetC_Activity_ID()); po.SetC_Campaign_ID(so.GetC_Campaign_ID()); po.SetC_Project_ID(so.GetC_Project_ID()); po.SetUser1_ID(so.GetUser1_ID()); po.SetUser2_ID(so.GetUser2_ID()); // po.Save(); return(po); }
/// <summary> /// Create Shipment /// </summary> /// <returns>info</returns> protected override String DoIt() { //log.info("C_Invoice_ID=" + _C_Invoice_ID // + ", M_Warehouse_ID=" + _M_Warehouse_ID // + ", C_DocType_ID=" + _C_DocType_ID); if (_C_Invoice_ID == 0) { throw new ArgumentException("@NotFound@ @C_Invoice_ID@"); } if (_M_Warehouse_ID == 0) { throw new ArgumentException("@NotFound@ @M_Warehouse_ID@"); } // MInvoice invoice = new MInvoice(GetCtx(), _C_Invoice_ID, null); if (invoice.Get_ID() == 0) { throw new ArgumentException("@NotFound@ @C_Invoice_ID@"); } if (!MInvoice.DOCSTATUS_Completed.Equals(invoice.GetDocStatus())) { throw new ArgumentException("@InvoiceCreateDocNotCompleted@"); } MDocType dt = MDocType.Get(GetCtx(), _C_DocType_ID); if (invoice.IsSOTrx() != dt.IsSOTrx() || invoice.IsReturnTrx() != dt.IsReturnTrx()) { throw new ArgumentException("@C_DocType_ID@ <> @C_Invoice_ID@"); } //*****************************Vikas 1 Dec 2015 ********************************* //Case Msg Not Showing Proper MInOut ship = null; MOrder ord = new MOrder(GetCtx(), invoice.GetC_Order_ID(), null); if (ord.GetC_BPartner_ID() > 0) { ship = new MInOut(invoice, _C_DocType_ID, null, _M_Warehouse_ID); // Change by Mohit Asked by Amardeep sir 02/03/2016 ship.SetPOReference(invoice.GetPOReference()); // End if (!ship.Save()) { return(GetRetrievedError(ship, "@SaveError@ Receipt")); // throw new ArgumentException("@SaveError@ Receipt"); } } else { return(GetRetrievedError(ship, "InvoiceNotLinkedWithPO")); //throw new ArgumentException("@InvoiceNotLinkedWithPO@"); } /* * MInOut ship = new MInOut(invoice, _C_DocType_ID, null, _M_Warehouse_ID); * if (!ship.Save()) * { * throw new ArgumentException("@SaveError@ Receipt"); * } */ //************************END***************************************** MInvoiceLine[] invoiceLines = invoice.GetLines(false); for (int i = 0; i < invoiceLines.Length; i++) { MInvoiceLine invoiceLine = invoiceLines[i]; MProduct product = invoiceLine.GetProduct(); // Nothing to Deliver // Get the lines of Invoice based on the setting taken on Tenant to allow non item Product if (Util.GetValueOfString(GetCtx().GetContext("$AllowNonItem")).Equals("N") && ((product != null && product.GetProductType() != MProduct.PRODUCTTYPE_Item) || invoiceLine.GetC_Charge_ID() != 0)) { continue; } MInOutLine sLine = new MInOutLine(ship); sLine.SetInvoiceLine(invoiceLine, 0, // Locator invoice.IsSOTrx() ? invoiceLine.GetQtyInvoiced() : Env.ZERO); sLine.SetQtyEntered(invoiceLine.GetQtyEntered()); sLine.SetMovementQty(invoiceLine.GetQtyInvoiced()); if (invoice.IsCreditMemo()) { sLine.SetQtyEntered(Decimal.Negate(sLine.GetQtyEntered())); //.negate()); sLine.SetMovementQty(Decimal.Negate(sLine.GetMovementQty())); //.negate()); } if (!sLine.Save()) { return(GetRetrievedError(sLine, "@SaveError@ @M_InOutLine_ID@")); //throw new ArgumentException("@SaveError@ @M_InOutLine_ID@"); } // invoiceLine.SetM_InOutLine_ID(sLine.GetM_InOutLine_ID()); if (!invoiceLine.Save()) { return(GetRetrievedError(invoiceLine, "@SaveError@ @C_InvoiceLine_ID@")); //throw new ArgumentException("@SaveError@ @C_InvoiceLine_ID@"); } } return(ship.GetDocumentNo()); }
/// <summary> /// Create actual Payment /// </summary> /// <param name="C_Invoice_ID">invoice</param> /// <param name="C_BPartner_ID">partner ignored when invoice exists</param> /// <param name="C_Currency_ID">currency</param> /// <param name="stmtAmt">statement amount</param> /// <param name="trxAmt">transaction amt</param> /// <param name="C_BankAccount_ID">bank account</param> /// <param name="dateTrx">transaction date</param> /// <param name="dateAcct">accounting date</param> /// <param name="description">description</param> /// <param name="AD_Org_ID"></param> /// <param name="C_ConversionType_ID">C_ConversionType_ID</param> /// <param name="C_Order_ID">C_Order_ID</param> /// <returns>payment</returns> private MPayment CreatePayment(int C_Invoice_ID, int C_BPartner_ID, int C_Currency_ID, Decimal stmtAmt, Decimal trxAmt, int C_BankAccount_ID, DateTime?dateTrx, DateTime?dateAcct, String description, int AD_Org_ID, int C_ConversionType_ID, int C_Order_ID) { // Trx Amount = Payment overwrites Statement Amount if defined Decimal payAmt = trxAmt; if (Env.ZERO.CompareTo(payAmt) == 0) { payAmt = stmtAmt; } if (C_Invoice_ID == 0 && C_Order_ID == 0 && (Env.ZERO.CompareTo(payAmt) == 0)) { throw new Exception("@PayAmt@ = 0"); } //if (payAmt == null) //{ // payAmt = Env.ZERO; //} // MPayment payment = new MPayment(GetCtx(), 0, Get_Trx()); payment.SetAD_Org_ID(AD_Org_ID); payment.SetC_BankAccount_ID(C_BankAccount_ID); //payment.SetTenderType(MPayment.TENDERTYPE_Check);//not required it will update on MPayment class //Get the C_ConversionType_ID from BankStatementLine and Set C_ConversionType_ID for Payment payment.SetC_ConversionType_ID(C_ConversionType_ID); if (dateTrx != null) { payment.SetDateTrx(dateTrx); } else if (dateAcct != null) { payment.SetDateTrx(dateAcct); } if (dateAcct != null) { payment.SetDateAcct(dateAcct); } else { payment.SetDateAcct(payment.GetDateTrx()); } payment.SetDescription(description); // if (C_Invoice_ID != 0) { MInvoice invoice = new MInvoice(GetCtx(), C_Invoice_ID, Get_Trx()); //Used Trx payment.SetC_DocType_ID(invoice.IsSOTrx()); // Receipt payment.SetC_BPartner_ID(invoice.GetC_BPartner_ID()); //set the BPartner Location from the Invoice payment.SetC_BPartner_Location_ID(invoice.GetC_BPartner_Location_ID()); //set the PaymentMethod by the reference of Invoice payment.SetVA009_PaymentMethod_ID(invoice.GetVA009_PaymentMethod_ID()); payment.SetC_Currency_ID(invoice.GetC_Currency_ID()); decimal _dueAmt = 0; string _sql = "SELECT * FROM C_InvoicePaySchedule WHERE VA009_PAIDAMNT IS NULL AND VA009_IsPaid = 'N' AND IsActive = 'Y' AND C_Invoice_ID =" + invoice.GetC_Invoice_ID(); DataSet _ds = DB.ExecuteDataset(_sql, null, Get_Trx()); if (_ds != null && _ds.Tables[0].Rows.Count == 1) { payment.SetC_Invoice_ID(invoice.GetC_Invoice_ID());//set Invoice Reference payment.SetC_InvoicePaySchedule_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[0]["C_INVOICEPAYSCHEDULE_ID"])); _dueAmt = Util.GetValueOfDecimal(_ds.Tables[0].Rows[0]["DUEAMT"]); //Set PayAmt -ve sign Incase of DocBaseType APC or ARC - IsReturnTrx is true //Set PayAmt +ve sign Incase of DocBaseType API or ARI - IsReturnTrx is false if (!invoice.IsReturnTrx()) { payment.SetPayAmt(_dueAmt); } else // payment is likely to be negative { payment.SetPayAmt(Decimal.Negate(_dueAmt)); } if (!payment.Save(Get_Trx())) { Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); //to get Exact Error Message first get Value from GetName() else GetValue() string error = pp != null?pp.GetName() : ""; if (string.IsNullOrEmpty(error)) { error = pp != null?pp.GetValue() : ""; if (string.IsNullOrEmpty(error)) { error = pp != null?pp.ToString() : ""; } } _message = !string.IsNullOrEmpty(error) ? error : "VA012_PaymentNotSaved"; return(null); } } else if (_ds != null && _ds.Tables[0].Rows.Count > 1) { if (!payment.Save(Get_Trx())) { Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); //to get Exact Error Message first get Value from GetName() else GetValue() string error = pp != null?pp.GetName() : ""; if (string.IsNullOrEmpty(error)) { error = pp != null?pp.GetValue() : ""; if (string.IsNullOrEmpty(error)) { error = pp != null?pp.ToString() : ""; } } _message = !string.IsNullOrEmpty(error) ? error : "VA012_PaymentNotSaved"; return(null); } else { //Initialize the Object for MPaymentAllocate class MPaymentAllocate PayAlocate = null; for (int i = 0; _ds.Tables[0].Rows.Count > i; i++) { //Create the Object for MPaymentAllocate class for every Iteration PayAlocate = new MPaymentAllocate(GetCtx(), 0, Get_Trx()); PayAlocate.SetC_Payment_ID(payment.GetC_Payment_ID()); PayAlocate.SetAD_Client_ID(payment.GetAD_Client_ID()); //set Organization with the reference of Bank Account PayAlocate.SetAD_Org_ID(payment.GetAD_Org_ID());//set Org_ID from the Header PayAlocate.SetC_Invoice_ID(invoice.GetC_Invoice_ID()); PayAlocate.SetC_InvoicePaySchedule_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["C_INVOICEPAYSCHEDULE_ID"])); //Set PayAmt -ve sign Incase of DocBaseType APC or ARC - IsReturnTrx is true //Set PayAmt +ve sign Incase of DocBaseType API or ARI - IsReturnTrx is false if (!invoice.IsReturnTrx()) { PayAlocate.SetInvoiceAmt(Util.GetValueOfDecimal(_ds.Tables[0].Rows[i]["DUEAMT"])); PayAlocate.SetAmount(Util.GetValueOfDecimal(_ds.Tables[0].Rows[i]["DUEAMT"])); } else { PayAlocate.SetInvoiceAmt(-1 * Util.GetValueOfDecimal(_ds.Tables[0].Rows[i]["DUEAMT"])); PayAlocate.SetAmount(-1 * Util.GetValueOfDecimal(_ds.Tables[0].Rows[i]["DUEAMT"])); } if (!PayAlocate.Save(Get_Trx())) { Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); //to get Exact Error Message first get Value from GetName() else GetValue() string error = pp != null?pp.GetName() : ""; if (string.IsNullOrEmpty(error)) { error = pp != null?pp.GetValue() : ""; if (string.IsNullOrEmpty(error)) { error = pp != null?pp.ToString() : ""; } } _message = !string.IsNullOrEmpty(error) ? error : "VA012_PaymentNotSaved"; return(null); } } } } } else if (C_Order_ID > 0 && C_BPartner_ID > 0) // Create Payment for prePayOrder reference { MOrder order = new MOrder(GetCtx(), C_Order_ID, Get_Trx()); payment.SetC_Order_ID(C_Order_ID); payment.SetC_DocType_ID(order.IsSOTrx()); // Receipt payment.SetC_BPartner_ID(order.GetC_BPartner_ID()); payment.SetC_BPartner_Location_ID(order.GetC_BPartner_Location_ID()); payment.SetC_Currency_ID(order.GetC_Currency_ID()); payment.SetVA009_PaymentMethod_ID(order.GetVA009_PaymentMethod_ID()); payment.SetPayAmt(order.GetGrandTotal()); if (!payment.Save(Get_Trx())) { Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); //to get Exact Error Message first get Value from GetName() else GetValue() string error = pp != null?pp.GetName() : ""; if (string.IsNullOrEmpty(error)) { error = pp != null?pp.GetValue() : ""; if (string.IsNullOrEmpty(error)) { error = pp != null?pp.ToString() : ""; } } _message = !string.IsNullOrEmpty(error) ? error : "VA012_PaymentNotSaved"; return(null); } } else { _message = "VA012_ReferenceNotfoundtoCreatePayment"; return(null); } //Commit the Transaction Get_Trx().Commit(); //Call Complete Method to Complete the Record //149 is AD_Process_ID for C_Payment_Process _message = CompletePayment(GetCtx(), payment.GetC_Payment_ID(), 149, MPayment.DOCACTION_Complete); if (!string.IsNullOrEmpty(_message)) { return(null); } return(payment); }
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> /// Apply Payment Term without schedule to Order /// </summary> /// <param name="order">Order</param> private void ApplyAdvanceTermSchedule(MOrder order) { //for(int i=0;i<_schedule.Length;i++)) StringBuilder _sql = new StringBuilder(); Decimal remainder = order.GetGrandTotal(); MVA009OrderPaySchedule schedule = new MVA009OrderPaySchedule(GetCtx(), 0, Get_TrxName()); MPaymentTerm payterm = new MPaymentTerm(GetCtx(), order.GetC_PaymentTerm_ID(), Get_TrxName()); schedule.SetAD_Client_ID(order.GetAD_Client_ID()); schedule.SetAD_Org_ID(order.GetAD_Org_ID()); schedule.SetC_Order_ID(order.GetC_Order_ID()); schedule.SetC_PaymentTerm_ID(order.GetC_PaymentTerm_ID()); schedule.SetVA009_PaymentMethod_ID(order.GetVA009_PaymentMethod_ID()); //schedule.SetDueDate(GetDueDate(order)); // Get Next Business Day if Next Business Days check box is set to true DateTime?payDueDate = null; if (payterm.IsNextBusinessDay()) { payDueDate = payterm.GetNextBusinessDate(TimeUtil.AddDays(order.GetDateOrdered(), payterm.GetNetDays())); } else { payDueDate = TimeUtil.AddDays(order.GetDateOrdered(), payterm.GetNetDays()); } schedule.SetDueDate(payDueDate); schedule.SetDueAmt(order.GetGrandTotal()); if (payterm.IsNextBusinessDay()) { payDueDate = payterm.GetNextBusinessDate(TimeUtil.AddDays(order.GetDateOrdered(), payterm.GetDiscountDays())); } else { payDueDate = TimeUtil.AddDays(order.GetDateOrdered(), payterm.GetDiscountDays()); } schedule.SetDiscountDate(payDueDate); //schedule.SetDiscountDate(order.GetDateOrdered().Value.AddDays(Util.GetValueOfInt(payterm.GetDiscountDays()))); schedule.SetDiscountAmt((Util.GetValueOfDecimal((order.GetGrandTotal() * payterm.GetDiscount()) / 100))); if (payterm.IsNextBusinessDay()) { payDueDate = payterm.GetNextBusinessDate(TimeUtil.AddDays(order.GetDateOrdered(), payterm.GetDiscountDays2())); } else { payDueDate = TimeUtil.AddDays(order.GetDateOrdered(), payterm.GetDiscountDays2()); } schedule.SetDiscountDays2(payDueDate); //schedule.SetDiscountDays2(order.GetDateOrdered().Value.AddDays(Util.GetValueOfInt(payterm.GetDiscountDays2()))); schedule.SetDiscount2((Util.GetValueOfDecimal((order.GetGrandTotal() * payterm.GetDiscount2()) / 100))); schedule.SetVA009_PlannedDueDate(GetDueDate(order)); int BaseCurrency = GetCtx().GetContextAsInt("$C_Currency_ID"); if (BaseCurrency != order.GetC_Currency_ID()) { decimal multiplyRate = MConversionRate.GetRate(order.GetC_Currency_ID(), BaseCurrency, order.GetDateAcct(), order.GetC_ConversionType_ID(), order.GetAD_Client_ID(), order.GetAD_Org_ID()); schedule.SetVA009_OpenAmnt(order.GetGrandTotal() * multiplyRate); } else { schedule.SetVA009_OpenAmnt(order.GetGrandTotal()); } schedule.SetC_Currency_ID(order.GetC_Currency_ID()); schedule.SetVA009_BseCurrncy(BaseCurrency); schedule.SetVA009_OpnAmntInvce(order.GetGrandTotal()); schedule.SetC_BPartner_ID(order.GetC_BPartner_ID()); MOrder _Order = new MOrder(GetCtx(), order.GetC_Order_ID(), Get_TrxName()); //schedule.SetVA009_PaymentMethod_ID(_Order.GetVA009_PaymentMethod_ID()); //schedule.SetC_PaymentTerm_ID(_Order.GetC_PaymentTerm_ID()); int _graceDay = payterm.GetGraceDays(); DateTime?_followUpDay = GetDueDate(order); schedule.SetVA009_FollowupDate(_followUpDay.Value.AddDays(_graceDay)); _sql.Clear(); _sql.Append("SELECT VA009_PaymentMode, VA009_PaymentType, VA009_PaymentTrigger FROM VA009_PaymentMethod WHERE VA009_PaymentMethod_ID=" + order.GetVA009_PaymentMethod_ID() + " AND IsActive = 'Y' AND AD_Client_ID = " + order.GetAD_Client_ID()); DataSet ds = new DataSet(); ds = DB.ExecuteDataset(_sql.ToString()); if (ds != null && ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { schedule.SetVA009_PaymentMode(Util.GetValueOfString(ds.Tables[0].Rows[0]["VA009_PaymentMode"])); schedule.SetVA009_PaymentType(Util.GetValueOfString(ds.Tables[0].Rows[0]["VA009_PaymentType"])); schedule.SetVA009_PaymentTrigger(Util.GetValueOfString(ds.Tables[0].Rows[0]["VA009_PaymentTrigger"])); schedule.SetVA009_ExecutionStatus("A"); } // updateInvoice if (!schedule.Save()) { ValueNamePair pp = VLogger.RetrieveError(); log.Info("Error found during creation of Order Schedule against Order ID = " + order.GetC_Order_ID() + " Error Name is " + pp.GetName()); } }
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> /// Create PO for Vendor /// </summary> /// <param name="C_BPartner_ID">vendor</param> /// <param name="so">sales order</param> /// <returns>MOrder</returns> public MOrder CreatePOForVendor(int C_BPartner_ID, MOrder so, string _shipDrop) { MOrder po = new MOrder(GetCtx(), 0, Get_TrxName()); po.SetClientOrg(so.GetAD_Client_ID(), so.GetAD_Org_ID()); po.SetRef_Order_ID(so.GetC_Order_ID()); po.SetIsSOTrx(false); // method edited to set unreleased document type for PO po.SetC_DocTypeTarget_ID(false); // po.SetDescription(so.GetDescription()); po.SetPOReference(so.GetDocumentNo()); po.SetPriorityRule(so.GetPriorityRule()); po.SetSalesRep_ID(so.GetSalesRep_ID()); // Code Commented by Vivek Kumar on 20/09/2017 Assigned By Pradeep for drop shipment //po.SetM_Warehouse_ID(so.GetM_Warehouse_ID()); // Set Vendor MBPartner vendor = new MBPartner(GetCtx(), C_BPartner_ID, Get_TrxName()); if (Env.IsModuleInstalled("VA009_")) { // Set PO Payment Method from Vendor if (Util.GetValueOfInt(vendor.GetVA009_PO_PaymentMethod_ID()) > 0) { po.SetVA009_PaymentMethod_ID(Util.GetValueOfInt(vendor.GetVA009_PO_PaymentMethod_ID())); } else { if (string.IsNullOrEmpty(messageErrorOrSetting.ToString())) { messageErrorOrSetting.Append(Msg.GetMsg(GetCtx(), "VIS_PaymentMethodNotDefined") + " : " + vendor.GetName()); } else { messageErrorOrSetting.Append(" , " + Msg.GetMsg(GetCtx(), "VIS_PaymentMethodNotDefined") + " : " + vendor.GetName()); } po = null; return(po); } } //JID_1252: If Vendor do not have Po Pricelist bind. System should give message. if (vendor.GetPO_PriceList_ID() > 0) { po.SetM_PriceList_ID(vendor.GetPO_PriceList_ID()); } else { if (string.IsNullOrEmpty(messageErrorOrSetting.ToString())) { messageErrorOrSetting.Append(Msg.GetMsg(GetCtx(), "VIS_VendorPrcListNotDefine") + " : " + vendor.GetName()); } else { messageErrorOrSetting.Append(" , " + Msg.GetMsg(GetCtx(), "VIS_VendorPrcListNotDefine") + " : " + vendor.GetName()); } po = null; return(po); } // JID_1262: If Payment Term is not bind BP, BP Group and No Default Payment Term. System do not create PO neither give message. if (vendor.GetPO_PaymentTerm_ID() > 0) { po.SetC_PaymentTerm_ID(vendor.GetPO_PaymentTerm_ID()); } else { if (string.IsNullOrEmpty(messageErrorOrSetting.ToString())) { messageErrorOrSetting.Append(Msg.GetMsg(GetCtx(), "VIS_VendorPaytemNotDefine") + " : " + vendor.GetName()); } else { messageErrorOrSetting.Append(" , " + Msg.GetMsg(GetCtx(), "VIS_VendorPaytemNotDefine") + " : " + vendor.GetName()); } po = null; return(po); } po.SetBPartner(vendor); // Code Commented by Vivek Kumar on 20/09/2017 Assigned By Pradeep for drop shipment // Drop Ship //po.SetIsDropShip(so.IsDropShip()); //if (so.IsDropShip()) //{ // po.SetShip_BPartner_ID(so.GetC_BPartner_ID()); // po.SetShip_Location_ID(so.GetC_BPartner_Location_ID()); // po.SetShip_User_ID(so.GetAD_User_ID()); //} if (_shipDrop == "Y") { po.SetIsDropShip(true); po.SetShipToPartner_ID(so.GetC_BPartner_ID()); po.SetShipToLocation_ID(so.GetC_BPartner_Location_ID()); int _Warehouse_ID = Util.GetValueOfInt(DB.ExecuteScalar("Select M_WareHouse_ID From M_Warehouse Where AD_Org_ID=" + so.GetAD_Org_ID() + " AND Isdropship='Y' AND IsActive='Y'")); if (_Warehouse_ID >= 0) { po.SetM_Warehouse_ID(_Warehouse_ID); } } // Added by Bharat on 29 Jan 2018 to set Inco Term from Order if (po.Get_ColumnIndex("C_IncoTerm_ID") > 0) { po.SetC_IncoTerm_ID(so.GetC_IncoTerm_ID()); } // References po.SetC_Activity_ID(so.GetC_Activity_ID()); po.SetC_Campaign_ID(so.GetC_Campaign_ID()); po.SetC_Project_ID(so.GetC_Project_ID()); po.SetUser1_ID(so.GetUser1_ID()); po.SetUser2_ID(so.GetUser2_ID()); //Set VA077 values on header level if (Env.IsModuleInstalled("VA077_")) { //Get the org count of legal entity org string sql = @"SELECT Count(AD_Org_ID) FROM AD_Org WHERE IsActive='Y' AND (IsProfitCenter ='Y' OR IsCostCenter ='Y') AND AD_Client_Id=" + so.GetAD_Client_ID() + @" AND LegalEntityOrg = " + so.GetAD_Org_ID(); int result = Util.GetValueOfInt(DB.ExecuteScalar(sql)); if (result > 0) { po.SetVA077_IsLegalEntity(true); } } // Handle error done by rakesh kumar on 17/Mar/2021 if (!po.Save()) { ValueNamePair pp = VLogger.RetrieveError(); string msg = string.Empty; if (pp != null) { msg = pp.GetName(); //if GetName is Empty then it will check GetValue if (string.IsNullOrEmpty(msg)) { msg = Msg.GetMsg("", pp.GetValue()); } } if (string.IsNullOrEmpty(msg)) { msg = Msg.GetMsg(GetCtx(), "RecordNotSaved"); } log.Info("CreatePOfromSO : Not Saved. Error Value : " + msg); AddLog(0, null, null, msg + " : @DocumentNo@ : " + so.GetDocumentNo()); } return(po); }