} // prepare /// <summary> /// Perform Process. /// </summary> /// <returns>Message (clear text)</returns> protected override String DoIt() { if (m_C_ProjectLine_ID == 0) { throw new ArgumentException("No Project Line"); } MProjectLine projectLine = new MProjectLine(GetCtx(), m_C_ProjectLine_ID, Get_TrxName()); log.Info("doIt - " + projectLine); if (projectLine.GetM_Product_ID() == 0) { throw new ArgumentException("No Product"); } // MProject project = new MProject(GetCtx(), projectLine.GetC_Project_ID(), Get_TrxName()); if (project.GetM_PriceList_ID() == 0) { throw new ArgumentException("No PriceList"); } // Boolean isSOTrx = true; MProductPricing pp = new MProductPricing(projectLine.GetAD_Client_ID(), projectLine.GetAD_Org_ID(), projectLine.GetM_Product_ID(), project.GetC_BPartner_ID(), projectLine.GetPlannedQty(), isSOTrx); pp.SetM_PriceList_ID(project.GetM_PriceList_ID()); //vikas mantis Issue ( 0000517) pp.SetM_PriceList_Version_ID(project.GetM_PriceList_Version_ID()); //End pp.SetPriceDate(project.GetDateContract()); // projectLine.SetPlannedPrice(pp.GetPriceStd()); //projectLine.SetPlannedMarginAmt(pp.GetPriceStd().subtract(pp.GetPriceLimit())); projectLine.SetPlannedMarginAmt(Decimal.Subtract(pp.GetPriceStd(), pp.GetPriceLimit())); projectLine.Save(); // String retValue = Msg.GetElement(GetCtx(), "PriceList") + pp.GetPriceList() + " - " + Msg.GetElement(GetCtx(), "PriceStd") + pp.GetPriceStd() + " - " + Msg.GetElement(GetCtx(), "PriceLimit") + pp.GetPriceLimit(); return(retValue); } // doIt
/// <summary> /// Generate Quotation /// </summary> /// <returns>Process Message</returns> protected override string DoIt() { // Int32 value = 0; string msg = ""; ValueNamePair vp = null; MBPartner bp = null; MOrderLine ol = null; log.Info("C_Project_ID=" + _C_Project_ID); if (_C_Project_ID == 0) { throw new ArgumentException("C_Project_ID == 0"); } MProject fromProject = new MProject(GetCtx(), _C_Project_ID, Get_TrxName()); if (fromProject.GetGenerate_Quotation() == null) { throw new ArgumentException("No Generate Quotation found on Project."); } if (fromProject.GetGenerate_Quotation().Trim() == "Y") { throw new ArgumentException("Sales Quotation already generated"); } // if Business Partner or Prospect is not selected then gives error if (fromProject.GetC_BPartner_ID() == 0 && fromProject.GetC_BPartnerSR_ID() == 0) { return(Msg.GetMsg(GetCtx(), "SelectBP/Prospect")); } //JID_1200: if Business Partner/Prospect Location is not selected then gives error if (fromProject.GetC_BPartner_Location_ID() == 0) { return(Msg.GetMsg(GetCtx(), "SelectBPLocation")); } MOrder order = new MOrder(GetCtx(), 0, Get_TrxName()); order.SetAD_Client_ID(fromProject.GetAD_Client_ID()); order.SetAD_Org_ID(fromProject.GetAD_Org_ID()); C_Bpartner_id = fromProject.GetC_BPartner_ID(); C_Bpartner_Location_id = fromProject.GetC_BPartner_Location_ID(); C_BPartnerSR_ID = fromProject.GetC_BPartnerSR_ID(); MBPartnerLocation bpartnerloc = new MBPartnerLocation(GetCtx(), C_Bpartner_Location_id, Get_TrxName()); //String currentdate = DateTime.Now.ToString(); String sqlprjln = "SELECT COUNT(C_ProjectLine_ID) FROM C_ProjectLine WHERE C_Project_ID=" + _C_Project_ID; C_ProjectLine_ID = Util.GetValueOfInt(DB.ExecuteScalar(sqlprjln, null, Get_TrxName())); if (C_ProjectLine_ID != 0) { order.SetDateOrdered(DateTime.Now.ToLocalTime()); order.SetDatePromised(DateTime.Now.ToLocalTime()); if (C_Bpartner_id != 0) { order.SetC_BPartner_ID(fromProject.GetC_BPartner_ID()); if (bpartnerloc.IsShipTo() == true) { order.SetC_BPartner_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetAD_User_ID(fromProject.GetAD_User_ID()); } if (bpartnerloc.IsBillTo() == true) { order.SetBill_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetBill_User_ID(fromProject.GetAD_User_ID()); } } if (C_BPartnerSR_ID != 0) { order.SetC_BPartner_ID(fromProject.GetC_BPartnerSR_ID()); if (bpartnerloc.IsShipTo() == true) { order.SetC_BPartner_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetAD_User_ID(fromProject.GetAD_User_ID()); } if (bpartnerloc.IsBillTo() == true) { order.SetBill_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetBill_User_ID(fromProject.GetAD_User_ID()); } } String sql = "SELECT C_DocType_ID FROM C_DocType WHERE DocBaseType = 'SOO' AND DocSubTypeSO = 'ON' AND IsReturnTrx = 'N' AND IsActive = 'Y' AND AD_Client_ID = " + GetCtx().GetAD_Client_ID() + " AND AD_Org_ID IN (0, " + GetAD_Org_ID() + ") ORDER BY AD_Org_ID DESC"; int Doctype_id = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_TrxName())); int MPriceList_id = fromProject.GetM_PriceList_ID(); order.SetM_PriceList_ID(MPriceList_id); order.SetC_Project_ID(GetRecord_ID()); if (fromProject.GetSalesRep_ID() > 0) { order.SetSalesRep_ID(fromProject.GetSalesRep_ID()); } order.SetC_Currency_ID(fromProject.GetC_Currency_ID()); if (C_Bpartner_id != 0) { bp = new MBPartner(GetCtx(), C_Bpartner_id, Get_TrxName()); if (bp.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0) { bp.SetC_Campaign_ID(fromProject.GetC_Campaign_ID()); } //bp.SetAD_Client_ID(fromProject.GetAD_Client_ID()); //bp.SetAD_Org_ID(fromProject.GetAD_Org_ID()); if (bp.GetC_PaymentTerm_ID() != 0) { order.SetPaymentMethod(bp.GetPaymentRule()); order.SetC_PaymentTerm_ID(bp.GetC_PaymentTerm_ID()); order.SetVA009_PaymentMethod_ID(bp.GetVA009_PaymentMethod_ID()); } if (!bp.Save()) { log.SaveError("BPartnerNotSaved", ""); return(Msg.GetMsg(GetCtx(), "BPartnerNotSaved")); } } else { bp = new MBPartner(GetCtx(), C_BPartnerSR_ID, Get_TrxName()); if (bp.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0) { bp.SetC_Campaign_ID(fromProject.GetC_Campaign_ID()); } //bp.SetAD_Client_ID(fromProject.GetAD_Client_ID()); //bp.SetAD_Org_ID(fromProject.GetAD_Org_ID()); if (bp.GetC_PaymentTerm_ID() != 0) { order.SetPaymentMethod(bp.GetPaymentRule()); order.SetC_PaymentTerm_ID(bp.GetC_PaymentTerm_ID()); order.SetVA009_PaymentMethod_ID(bp.GetVA009_PaymentMethod_ID()); } if (!bp.Save()) { log.SaveError("BPartnerNotSaved", ""); return(Msg.GetMsg(GetCtx(), "BPartnerNotSaved")); } } order.SetFreightCostRule("I"); if (order.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0) { order.SetC_Campaign_ID(fromProject.GetC_Campaign_ID()); } order.SetDocStatus("IP"); order.SetC_DocType_ID(Doctype_id); order.SetC_DocTypeTarget_ID(Doctype_id); order.SetIsSOTrx(true); order.Set_Value("IsSalesQuotation", true); //Set VA077 values on header level if (Env.IsModuleInstalled("VA077_")) { //Get the org count of legal entity org sql = @"SELECT Count(AD_Org_ID) FROM AD_Org WHERE IsActive='Y' AND (IsProfitCenter ='Y' OR IsCostCenter ='Y') AND AD_Client_Id=" + fromProject.GetAD_Client_ID() + @" AND LegalEntityOrg = " + fromProject.GetAD_Org_ID(); int result = Util.GetValueOfInt(DB.ExecuteScalar(sql)); if (result > 0) { order.SetVA077_IsLegalEntity(true); } order.SetVA077_SalesCoWorker(fromProject.GetVA077_SalesCoWorker()); order.SetVA077_SalesCoWorkerPer(fromProject.GetVA077_SalesCoWorkerPer()); order.Set_Value("VA077_TotalMarginAmt", fromProject.Get_Value("VA077_TotalMarginAmt")); order.Set_Value("VA077_TotalPurchaseAmt", fromProject.Get_Value("VA077_TotalPurchaseAmt")); order.Set_Value("VA077_TotalSalesAmt", fromProject.Get_Value("VA077_TotalSalesAmt")); order.Set_Value("VA077_MarginPercent", fromProject.Get_Value("VA077_MarginPercent")); } if (!order.Save()) { Get_TrxName().Rollback(); vp = VLogger.RetrieveError(); if (vp != null) { msg = vp.GetName(); } else { msg = Msg.GetMsg(GetCtx(), "QuotationNotSaved"); } log.SaveError("QuotationNotSaved", ""); return(msg); } //Order Lines int count = 0; MProjectLine[] lines = fromProject.GetLines(); for (int i = 0; i < lines.Length; i++) { ol = new MOrderLine(order); ol.SetLine(lines[i].GetLine()); ol.SetDescription(lines[i].GetDescription()); ol.SetM_Product_ID(lines[i].GetM_Product_ID(), true); ol.SetQtyEntered(lines[i].GetPlannedQty()); ol.SetQtyOrdered(lines[i].GetPlannedQty()); ol.SetPriceEntered(lines[i].GetPlannedPrice()); ol.SetPriceActual(lines[i].GetPlannedPrice()); ol.SetPriceList(lines[i].GetPriceList()); //Set VA077 values on line level if (Env.IsModuleInstalled("VA077_")) { ol.Set_Value("VA077_MarginPercent", lines[i].Get_Value("VA077_MarginPercent")); ol.Set_Value("VA077_MarginAmt", lines[i].Get_Value("VA077_MarginAmt")); ol.Set_Value("VA077_PurchasePrice", lines[i].Get_Value("VA077_PurchasePrice")); } if (ol.Save()) { count++; } else { Get_TrxName().Rollback(); vp = VLogger.RetrieveError(); if (vp != null) { msg = vp.GetName(); } else { msg = Msg.GetMsg(GetCtx(), "QuoteLineNotSaved"); } log.SaveError("QuoteLineNotSaved", ""); return(msg); } } fromProject.SetRef_Order_ID(order.GetC_Order_ID()); fromProject.SetGenerate_Quotation("Y"); if (!fromProject.Save()) { Get_TrxName().Rollback(); log.SaveError("ProjectNotSaved", ""); return(Msg.GetMsg(GetCtx(), "ProjectNotSaved")); } msg = Msg.GetMsg(GetCtx(), "QuotationGenerated"); } else { msg = Msg.GetMsg(GetCtx(), "NoLines"); } return(msg); }
} // 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
} // prepare /// <summary> /// Generate Sales Order /// </summary> /// <returns>Process Message</returns> protected override String DoIt() { Int32 value = 0; string msg = ""; ValueNamePair vp = null; MBPartner bp = null; MOrderLine ol = null; log.Info("C_Project_ID=" + _C_Project_ID); if (_C_Project_ID == 0) { throw new ArgumentException("C_Project_ID == 0"); } MProject fromProject = new MProject(GetCtx(), _C_Project_ID, Get_TrxName()); if (fromProject.GetGenerate_Order().Trim() == "Y") { throw new ArgumentException("Sales Order already generated"); } // if Business Partner or Prospect is not selected then gives error if (fromProject.GetC_BPartner_ID() == 0 && fromProject.GetC_BPartnerSR_ID() == 0) { return(Msg.GetMsg(GetCtx(), "SelectBP/Prospect")); } // if Business Partner/Prospect Location is not selected then gives error if (fromProject.GetC_BPartner_Location_ID() == 0) { return(Msg.GetMsg(GetCtx(), "SelectBPLocation")); } MOrder order = new MOrder(GetCtx(), 0, Get_TrxName()); order.SetAD_Client_ID(fromProject.GetAD_Client_ID()); order.SetAD_Org_ID(fromProject.GetAD_Org_ID()); C_Bpartner_id = fromProject.GetC_BPartner_ID(); C_Bpartner_Location_id = fromProject.GetC_BPartner_Location_ID(); C_BPartnerSR_ID = fromProject.GetC_BPartnerSR_ID(); MBPartnerLocation bpartnerloc = new MBPartnerLocation(GetCtx(), C_Bpartner_Location_id, Get_TrxName()); //String currentdate = DateTime.Now.ToString(); String sqlprjln = "SELECT COUNT(C_ProjectLine_ID) FROM C_ProjectLine WHERE C_Project_ID=" + _C_Project_ID; C_ProjectLine_ID = Util.GetValueOfInt(DB.ExecuteScalar(sqlprjln, null, Get_TrxName())); if (C_ProjectLine_ID != 0) { order.SetDateOrdered(DateTime.Now.ToLocalTime()); order.SetDatePromised(DateTime.Now.ToLocalTime()); if (C_Bpartner_id != 0) { order.SetC_BPartner_ID(fromProject.GetC_BPartner_ID()); if (bpartnerloc.IsShipTo() == true) { order.SetC_BPartner_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetAD_User_ID(fromProject.GetAD_User_ID()); } if (bpartnerloc.IsBillTo() == true) { order.SetBill_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetBill_User_ID(fromProject.GetAD_User_ID()); } } if (C_BPartnerSR_ID != 0) { String sqlcust = "UPDATE C_BPartner SET IsCustomer='Y', IsProspect='N' WHERE C_BPartner_ID=" + C_BPartnerSR_ID; value = DB.ExecuteQuery(sqlcust, null, Get_TrxName()); if (value == -1) { return(Msg.GetMsg(GetCtx(), "BPartnerNotSaved")); } order.SetC_BPartner_ID(fromProject.GetC_BPartnerSR_ID()); if (bpartnerloc.IsShipTo() == true) { order.SetC_BPartner_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetAD_User_ID(fromProject.GetAD_User_ID()); } if (bpartnerloc.IsBillTo() == true) { order.SetBill_Location_ID(fromProject.GetC_BPartner_Location_ID()); order.SetBill_User_ID(fromProject.GetAD_User_ID()); } } String sql = "SELECT C_DocType_ID FROM C_DocType WHERE DocBaseType = 'SOO' AND DocSubTypeSO = 'SO' AND IsReturnTrx = 'N' AND IsActive = 'Y' AND AD_Client_ID = " + GetAD_Client_ID() + " AND AD_Org_ID IN (0, " + GetAD_Org_ID() + ") ORDER BY AD_Org_ID DESC"; int Doctype_id = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_TrxName())); order.SetM_PriceList_ID(fromProject.GetM_PriceList_ID()); order.SetC_Project_ID(GetRecord_ID()); if (fromProject.GetSalesRep_ID() > 0) { order.SetSalesRep_ID(fromProject.GetSalesRep_ID()); } order.SetC_Currency_ID(fromProject.GetC_Currency_ID()); if (C_Bpartner_id != 0) { bp = new MBPartner(GetCtx(), C_Bpartner_id, Get_TrxName()); if (bp.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0) { bp.SetC_Campaign_ID(fromProject.GetC_Campaign_ID()); } //bp.SetAD_Client_ID(fromProject.GetAD_Client_ID()); //bp.SetAD_Org_ID(fromProject.GetAD_Org_ID()); if (bp.GetC_PaymentTerm_ID() != 0) { order.SetPaymentMethod(bp.GetPaymentRule()); order.SetC_PaymentTerm_ID(bp.GetC_PaymentTerm_ID()); } if (!bp.Save()) { log.SaveError("BPartnerNotSaved", ""); return(Msg.GetMsg(GetCtx(), "BPartnerNotSaved")); } } else { bp = new MBPartner(GetCtx(), C_BPartnerSR_ID, Get_TrxName()); if (bp.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0) { bp.SetC_Campaign_ID(fromProject.GetC_Campaign_ID()); } //bp.SetAD_Client_ID(fromProject.GetAD_Client_ID()); //bp.SetAD_Org_ID(fromProject.GetAD_Org_ID()); if (bp.GetC_PaymentTerm_ID() != 0) { order.SetPaymentMethod(bp.GetPaymentRule()); order.SetC_PaymentTerm_ID(bp.GetC_PaymentTerm_ID()); } if (!bp.Save()) { log.SaveError("BPartnerNotSaved", ""); return(Msg.GetMsg(GetCtx(), "BPartnerNotSaved")); } } order.SetFreightCostRule("I"); if (order.GetC_Campaign_ID() == 0 && fromProject.GetC_Campaign_ID() > 0) { order.SetC_Campaign_ID(fromProject.GetC_Campaign_ID()); } order.SetDocStatus("IP"); order.SetC_DocType_ID(Doctype_id); order.SetIsSOTrx(true); order.SetC_DocTypeTarget_ID(Doctype_id); order.SetPriorityRule("5"); order.SetFreightCostRule("I"); if (!order.Save()) { Get_TrxName().Rollback(); vp = VLogger.RetrieveError(); if (vp != null) { msg = vp.GetName(); } else { msg = Msg.GetMsg(GetCtx(), "SaleOrderNotSaved"); } log.SaveError("SaleOrderNotSaved", ""); return(msg); } //Order Lines int count = 0; MProjectLine[] lines = fromProject.GetLines(); for (int i = 0; i < lines.Length; i++) { ol = new MOrderLine(order); ol.SetLine(lines[i].GetLine()); ol.SetDescription(lines[i].GetDescription()); ol.SetM_Product_ID(lines[i].GetM_Product_ID(), true); ol.SetQtyEntered(lines[i].GetPlannedQty()); ol.SetQtyOrdered(lines[i].GetPlannedQty()); ol.SetPriceEntered(lines[i].GetPlannedPrice()); ol.SetPriceActual(lines[i].GetPlannedPrice()); ol.SetPriceList(lines[i].GetPriceList()); if (ol.Save()) { count++; } else { Get_TrxName().Rollback(); vp = VLogger.RetrieveError(); if (vp != null) { msg = vp.GetName(); } else { msg = Msg.GetMsg(GetCtx(), "OrderLineNotSaved"); } log.SaveError("OrderLineNotSaved", ""); return(msg); } } fromProject.SetC_Order_ID(order.GetC_Order_ID()); fromProject.SetC_BPartner_ID(fromProject.GetC_BPartnerSR_ID()); fromProject.SetC_BPartnerSR_ID(0); fromProject.SetGenerate_Order("Y"); if (!fromProject.Save()) { Get_TrxName().Rollback(); log.SaveError("ProjectNotSaved", ""); return(Msg.GetMsg(GetCtx(), "ProjectNotSaved")); } return(Msg.GetMsg(GetCtx(), "OrderGenerationDone")); } else { msg = Msg.GetMsg(GetCtx(), "NoLines"); } return(msg); }