/// <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 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); }
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); }
/** * 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); } }
/** * 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> /// 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()); } }
/// <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 }
} // doIt /// <summary> /// Process Expense Line /// </summary> /// <param name="te">header</param> /// <param name="tel">line</param> /// <param name="bp">bp</param> private void ProcessLine(MTimeExpense te, MTimeExpenseLine tel, MBPartner bp) { if (_order == null) { log.Info("New Order for " + bp + ", Project=" + tel.GetC_Project_ID()); _order = new MOrder(GetCtx(), 0, Get_TrxName()); _order.SetAD_Org_ID(tel.GetAD_Org_ID()); _order.SetC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard); // _order.SetBPartner(bp); if (_order.GetC_BPartner_Location_ID() == 0) { log.Log(Level.SEVERE, "No BP Location: " + bp); AddLog(0, te.GetDateReport(), null, "No Location: " + te.GetDocumentNo() + " " + bp.GetName()); _order = null; return; } _order.SetM_Warehouse_ID(te.GetM_Warehouse_ID()); ////Added By Arpit asked by Surya Sir..................29-12-2015 //_order.SetSalesRep_ID(GetCtx().GetAD_User_ID()); //End if (tel.GetC_Activity_ID() != 0) { _order.SetC_Activity_ID(tel.GetC_Activity_ID()); } if (tel.GetC_Campaign_ID() != 0) { _order.SetC_Campaign_ID(tel.GetC_Campaign_ID()); } if (tel.GetC_Project_ID() != 0) { _order.SetC_Project_ID(tel.GetC_Project_ID()); // Optionally Overwrite BP Price list from Project MProject project = new MProject(GetCtx(), tel.GetC_Project_ID(), Get_TrxName()); if (project.GetM_PriceList_ID() != 0) { _order.SetM_PriceList_ID(project.GetM_PriceList_ID()); } } _order.SetSalesRep_ID(te.GetDoc_User_ID()); // if (!_order.Save()) { throw new Exception("Cannot save Order"); } } else { // Update Header info if (tel.GetC_Activity_ID() != 0 && tel.GetC_Activity_ID() != _order.GetC_Activity_ID()) { _order.SetC_Activity_ID(tel.GetC_Activity_ID()); } if (tel.GetC_Campaign_ID() != 0 && tel.GetC_Campaign_ID() != _order.GetC_Campaign_ID()) { _order.SetC_Campaign_ID(tel.GetC_Campaign_ID()); } if (!_order.Save()) { new Exception("Cannot save Order"); } } // OrderLine MOrderLine ol = new MOrderLine(_order); // if (tel.GetM_Product_ID() != 0) { ol.SetM_Product_ID(tel.GetM_Product_ID(), tel.GetC_UOM_ID()); } if (tel.GetS_ResourceAssignment_ID() != 0) { ol.SetS_ResourceAssignment_ID(tel.GetS_ResourceAssignment_ID()); } // Set charge ID if (tel.GetC_Charge_ID() != 0) { ol.SetC_Charge_ID(tel.GetC_Charge_ID()); ol.SetPriceActual(tel.GetExpenseAmt()); ol.SetQty(tel.GetQty()); } ol.SetQty(tel.GetQtyInvoiced()); // ol.SetDescription(tel.GetDescription()); // ol.SetC_Project_ID(tel.GetC_Project_ID()); ol.SetC_ProjectPhase_ID(tel.GetC_ProjectPhase_ID()); ol.SetC_ProjectTask_ID(tel.GetC_ProjectTask_ID()); ol.SetC_Activity_ID(tel.GetC_Activity_ID()); ol.SetC_Campaign_ID(tel.GetC_Campaign_ID()); // Decimal price = tel.GetPriceInvoiced(); // if (price.CompareTo(Env.ZERO) != 0) { if (tel.GetC_Currency_ID() != _order.GetC_Currency_ID()) { price = MConversionRate.Convert(GetCtx(), price, tel.GetC_Currency_ID(), _order.GetC_Currency_ID(), _order.GetAD_Client_ID(), _order.GetAD_Org_ID()); } ol.SetPrice(price); } else { ol.SetPrice(); } if (tel.GetC_UOM_ID() != 0 && ol.GetC_UOM_ID() == 0) { ol.SetC_UOM_ID(tel.GetC_UOM_ID()); } ol.SetTax(); if (!ol.Save()) { throw new Exception("Cannot save Order Line"); } // Update TimeExpense Line tel.SetC_OrderLine_ID(ol.GetC_OrderLine_ID()); if (tel.Save()) { log.Fine("Updated " + tel + " with C_OrderLine_ID"); } else { log.Log(Level.SEVERE, "Not Updated " + tel + " with C_OrderLine_ID"); } } // processLine
} // doIt /// <summary> /// Process Expense Line /// </summary> /// <param name="te">header</param> /// <param name="tel">line</param> /// <param name="bp">bp</param> private void ProcessLine(MTimeExpense te, MTimeExpenseLine tel, MBPartner bp) { if (_order == null) { log.Info("New Order for " + bp + ", Project=" + tel.GetC_Project_ID()); _order = new MOrder(GetCtx(), 0, Get_TrxName()); _order.SetAD_Org_ID(tel.GetAD_Org_ID()); _order.SetC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard); // _order.SetBPartner(bp); if (_order.GetC_BPartner_Location_ID() == 0) { log.Log(Level.SEVERE, "No BP Location: " + bp); AddLog(0, te.GetDateReport(), null, "No Location: " + te.GetDocumentNo() + " " + bp.GetName()); _order = null; return; } _order.SetM_Warehouse_ID(te.GetM_Warehouse_ID()); //Bhupendra: Add payment term // to check for if payment term is null if (bp.GetC_PaymentTerm_ID() == 0) { // set the default payment method as check int payTerm = GetPaymentTerm(); if (payTerm <= 0) { message = Msg.GetMsg(GetCtx(), "IsActivePaymentTerm"); return; } else { _order.SetC_PaymentTerm_ID(payTerm); } } else { //check weather paymentterm is active or not if (Util.GetValueOfString(DB.ExecuteScalar("SELECT IsActive FROM C_PaymentTerm WHERE C_PaymentTerm_ID=" + bp.GetC_PaymentTerm_ID(), null, Get_Trx())).Equals("Y")) { _order.SetC_PaymentTerm_ID(bp.GetC_PaymentTerm_ID()); } else { message = Msg.GetMsg(GetCtx(), "IsActivePaymentTerm"); return; } } // Bhupendra: added a cond to check for payment method if null // Added by mohit - to set payment method and sales rep id. if (bp.GetVA009_PaymentMethod_ID() == 0) { // set the default payment method as check int paymethod = GetPaymentMethod(); if (paymethod <= 0) { message = Msg.GetMsg(GetCtx(), "IsActivePaymentMethod"); return; } else { _order.SetVA009_PaymentMethod_ID(paymethod); } } else { //check weather the PaymentMethod is active or not if (Util.GetValueOfString(DB.ExecuteScalar("SELECT IsActive FROM VA009_PaymentMethod WHERE VA009_PaymentMethod_ID=" + bp.GetVA009_PaymentMethod_ID(), null, Get_Trx())).Equals("Y")) { _order.SetVA009_PaymentMethod_ID(bp.GetVA009_PaymentMethod_ID()); } else { message = Msg.GetMsg(GetCtx(), "IsActivePaymentMethod"); return; } } _order.SetSalesRep_ID(te.GetDoc_User_ID()); ////Added By Arpit asked by Surya Sir..................29-12-2015 //_order.SetSalesRep_ID(GetCtx().GetAD_User_ID()); //End if (tel.GetC_Activity_ID() != 0) { _order.SetC_Activity_ID(tel.GetC_Activity_ID()); } if (tel.GetC_Campaign_ID() != 0) { _order.SetC_Campaign_ID(tel.GetC_Campaign_ID()); } if (tel.GetC_Project_ID() != 0) { _order.SetC_Project_ID(tel.GetC_Project_ID()); // Optionally Overwrite BP Price list from Project MProject project = new MProject(GetCtx(), tel.GetC_Project_ID(), Get_TrxName()); if (project.GetM_PriceList_ID() != 0) { //check weather the PriceList is active or not if (Util.GetValueOfString(DB.ExecuteScalar("SELECT IsActive FROM M_PriceList WHERE M_PriceList_ID=" + project.GetM_PriceList_ID(), null, Get_Trx())).Equals("Y")) { _order.SetM_PriceList_ID(project.GetM_PriceList_ID()); } else { message = Msg.GetMsg(GetCtx(), "IsActivePriceList"); return; } } } else { if (bp.GetM_PriceList_ID() != 0) { if (Util.GetValueOfString(DB.ExecuteScalar("SELECT IsActive FROM M_PriceList WHERE M_PriceList_ID=" + bp.GetM_PriceList_ID(), null, Get_Trx())).Equals("Y")) { _order.SetM_PriceList_ID(bp.GetM_PriceList_ID()); } else { message = Msg.GetMsg(GetCtx(), "IsActivePriceList"); return; } } } _order.SetSalesRep_ID(te.GetDoc_User_ID()); // if (!_order.Save()) { Rollback(); ValueNamePair pp = VLogger.RetrieveError(); if (pp != null) { message = pp.GetName(); //if GetName is Empty then it will check GetValue if (string.IsNullOrEmpty(message)) { message = Msg.GetMsg("", pp.GetValue()); } } if (string.IsNullOrEmpty(message)) { message = Msg.GetMsg(GetCtx(), "CantSaveOrder"); } return; //throw new Exception("Cannot save Order"); } } else { // Update Header info if (tel.GetC_Activity_ID() != 0 && tel.GetC_Activity_ID() != _order.GetC_Activity_ID()) { _order.SetC_Activity_ID(tel.GetC_Activity_ID()); } if (tel.GetC_Campaign_ID() != 0 && tel.GetC_Campaign_ID() != _order.GetC_Campaign_ID()) { _order.SetC_Campaign_ID(tel.GetC_Campaign_ID()); } if (!_order.Save()) { Rollback(); //get error message from ValueNamePair ValueNamePair pp = VLogger.RetrieveError(); if (pp != null) { message = pp.GetName(); //if GetName is Empty then it will check GetValue if (string.IsNullOrEmpty(message)) { message = Msg.GetMsg("", pp.GetValue()); } } //it will check message is null or not if (string.IsNullOrEmpty(message)) { message = Msg.GetMsg(GetCtx(), "CantSaveOrder"); } return; //new Exception("Cannot save Order"); } } // OrderLine MOrderLine ol = new MOrderLine(_order); // if (tel.GetM_Product_ID() != 0) { ol.SetM_Product_ID(tel.GetM_Product_ID(), tel.GetC_UOM_ID()); } if (tel.GetS_ResourceAssignment_ID() != 0) { ol.SetS_ResourceAssignment_ID(tel.GetS_ResourceAssignment_ID()); } // Set charge ID if (tel.GetC_Charge_ID() != 0) { ol.SetC_Charge_ID(tel.GetC_Charge_ID()); ol.SetPriceActual(tel.GetExpenseAmt()); ol.SetQty(tel.GetQty()); } ol.SetQty(tel.GetQtyInvoiced()); // ol.SetDescription(tel.GetDescription()); // ol.SetC_Project_ID(tel.GetC_Project_ID()); ol.SetC_ProjectPhase_ID(tel.GetC_ProjectPhase_ID()); ol.SetC_ProjectTask_ID(tel.GetC_ProjectTask_ID()); ol.SetC_Activity_ID(tel.GetC_Activity_ID()); ol.SetC_Campaign_ID(tel.GetC_Campaign_ID()); // Decimal price = tel.GetPriceInvoiced(); // if (price.CompareTo(Env.ZERO) != 0) { if (tel.GetC_Currency_ID() != _order.GetC_Currency_ID()) { price = MConversionRate.Convert(GetCtx(), price, tel.GetC_Currency_ID(), _order.GetC_Currency_ID(), _order.GetAD_Client_ID(), _order.GetAD_Org_ID()); } ol.SetPrice(price); // added by Bhupendra to set the entered price ol.SetPriceEntered(price); } else { ol.SetPrice(); } if (tel.GetC_UOM_ID() != 0 && ol.GetC_UOM_ID() == 0) { ol.SetC_UOM_ID(tel.GetC_UOM_ID()); } ol.SetTax(); if (!ol.Save()) { Rollback(); //get error message from ValueNamePair ValueNamePair pp = VLogger.RetrieveError(); if (pp != null) { message = pp.GetName(); //if GetName is Empty then it will check GetValue if (string.IsNullOrEmpty(message)) { message = Msg.GetMsg("", pp.GetValue()); } } //it will check message is null or not if (string.IsNullOrEmpty(message)) { message = Msg.GetMsg(GetCtx(), "CantSaveOrderLine"); } return; //throw new Exception("Cannot save Order Line"); } // Update TimeExpense Line tel.SetC_OrderLine_ID(ol.GetC_OrderLine_ID()); if (tel.Save()) { log.Fine("Updated " + tel + " with C_OrderLine_ID"); } else { log.Log(Level.SEVERE, "Not Updated " + tel + " with C_OrderLine_ID"); } } // processLine
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, Get_TrxName()); 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("Order Type must be Prepay Order or Credit Order."); } MPayment payment = new MPayment(GetCtx(), 0, Get_TrxName()); 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"); C_DocType_ID = Util.GetValueOfInt(DB.ExecuteScalar("SELECT C_DocType_ID From C_DocType WHERE isactive='Y' AND DocBaseType = 'ARR' AND AD_Client_ID = " + order.GetAD_Client_ID() + " ORDER BY IsDefault DESC")); payment.SetC_DocType_ID(C_DocType_ID); 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 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 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); }