} // generatePaySelect /// <summary> /// Create Check /// </summary> /// <param name="ctx"></param> /// <param name="line"></param> /// <param name="_list"></param> private void CreateCheck(Ctx ctx, MPaySelectionLine line, List <MPaySelectionCheck> _list) { string _PaymentRule = "S"; if (_PaymentRule != null && _PaymentRule.Equals(X_C_Order.PAYMENTRULE_DirectDebit)) { _PaymentRule = null; } //// Try to find one for (int i = 0; i < _list.Count; i++) { MPaySelectionCheck check = (MPaySelectionCheck)_list[i]; // Add to existing if (check.GetC_BPartner_ID() == line.GetInvoice().GetC_BPartner_ID()) { check.AddLine(line); if (!check.Save()) { throw new Exception("Cannot save MPaySelectionCheck"); } line.SetC_PaySelectionCheck_ID(check.GetC_PaySelectionCheck_ID()); line.SetProcessed(true); if (!line.Save()) { throw new Exception("Cannot save MPaySelectionLine"); } return; } } //// Create new String PaymentRule = line.GetPaymentRule(); if (_PaymentRule != null && _PaymentRule != " ") { if (!X_C_Order.PAYMENTRULE_DirectDebit.Equals(PaymentRule)) { PaymentRule = _PaymentRule; } } MPaySelectionCheck check1 = new MPaySelectionCheck(line, PaymentRule); if (!check1.IsValid()) { int C_BPartner_ID = check1.GetC_BPartner_ID(); MBPartner bp = MBPartner.Get(ctx, C_BPartner_ID); String msg = "@NotFound@ @C_BP_BankAccount@: " + bp.GetName(); throw new Exception(msg); } if (!check1.Save()) { throw new Exception("Cannot save MPaySelectionCheck"); } line.SetC_PaySelectionCheck_ID(check1.GetC_PaySelectionCheck_ID()); line.SetProcessed(true); if (!line.Save()) { throw new Exception("Cannot save MPaySelectionLine"); } _list.Add(check1); }
/** * * * /** * Set Value Name Description * @param Invoice * @param line line * @param deliveryCount */ public void SetValueNameDescription(MInvoice invoice, MInvoiceLine line, int deliveryCount) { MProduct product = line.GetProduct(); MBPartner partner = new MBPartner(GetCtx(), invoice.GetC_BPartner_ID(), null); SetValueNameDescription(invoice, deliveryCount, product, partner); }
/** * Set Value, Name, Description * @param invoice * @param deliveryCount count * @param product product * @param partner partner */ public void SetValueNameDescription(MInvoice invoice, int deliveryCount, MProduct product, MBPartner partner) { String documentNo = "_" + invoice.GetDocumentNo(); if (deliveryCount > 1) { documentNo += "_" + deliveryCount; } // Value String value = partner.GetValue() + "_" + product.GetValue(); if (value.Length > 40 - documentNo.Length) { value = value.Substring(0, 40 - documentNo.Length) + documentNo; } // Change to set Value from Document Sequence // SetValue(value); // Change to set only name of product as value in Asset // Name MProduct.afterSave // String name = partner.GetName() + " - " + product.GetName(); String name = product.GetName(); if (name.Length > 60) { name = name.Substring(0, 60); } SetName(name); // Description String description = product.GetDescription(); SetDescription(description); }
/// <summary> /// Dunning Level Consequences /// </summary> /// <param name="level"></param> /// <param name="entry"></param> private void DunningLevelConsequences(MDunningLevel level, MDunningRunEntry entry) { // Update Business Partner based on Level if (level.IsSetCreditStop() || level.IsSetPaymentTerm()) { MBPartner thisBPartner = new MBPartner(GetCtx(), entry.GetC_BPartner_ID(), Get_TrxName()); if (level.IsSetCreditStop()) { thisBPartner.SetSOCreditStatus(X_C_BPartner.SOCREDITSTATUS_CreditStop); } if (level.IsSetPaymentTerm() && level.GetC_PaymentTerm_ID() != 0) { thisBPartner.SetC_PaymentTerm_ID(level.GetC_PaymentTerm_ID()); } thisBPartner.Save(); } // Update Invoices if not Statement (Statement is hardcoded -9999 see also MDunningLevel) if (!level.GetDaysAfterDue().Equals(new Decimal(-9999)) && level.GetInvoiceCollectionType() != null) { MDunningRunLine[] lines = entry.GetLines(); for (int i = 0; i < lines.Length; i++) { MDunningRunLine line = lines[i]; if (line.GetC_Invoice_ID() != 0 && line.IsActive()) { MInvoice invoice = new MInvoice(GetCtx(), line.GetC_Invoice_ID(), Get_TrxName()); invoice.SetInvoiceCollectionType(level.GetInvoiceCollectionType()); invoice.Save(); } } } }
/** * Set Value Name Description * @param shipment shipment * @param line line * @param deliveryCount */ public void SetValueNameDescription(MInOut shipment, MInOutLine line, int deliveryCount) { VAdvantage.Model.MProduct product = line.GetProduct(); MBPartner partner = shipment.GetBPartner(); SetValueNameDescription(shipment, deliveryCount, product, partner); }
} // prepare /// <summary> /// Perform Process. /// </summary> /// <returns>Message (text with variables)</returns> protected override String DoIt() { log.Info("doIt - C_BPartner_ID=" + _C_BPartner_ID); if (_C_BPartner_ID == 0) { throw new ArgumentException("No Business Partner ID"); } MBPartner bp = new MBPartner(GetCtx(), _C_BPartner_ID, Get_Trx()); if (bp.Get_ID() == 0) { throw new ArgumentException("Business Partner not found - C_BPartner_ID=" + _C_BPartner_ID); } // if (bp.GetAD_OrgBP_ID_Int() == 0) { throw new ArgumentException("Business Partner not linked to an Organization"); } bp.SetAD_OrgBP_ID(null); if (!bp.Save()) { return(GetRetrievedError(bp, "Business Partner not changed")); //throw new ArgumentException("Business Partner not changed"); } return("OK"); } // doIt
} // prepare /// <summary> /// Process /// </summary> /// <returns>info</returns> protected override String DoIt() { log.Info("C_BPartner_ID=" + _C_BPartner_ID + ", C_BP_Group_ID=" + _C_BP_Group_ID); if (_C_BP_Group_ID == -1) { _C_BP_Group_ID = 0; } if (_C_BPartner_ID == 0 && _C_BP_Group_ID == 0) { throw new Exception("No Business Partner/Group selected"); } if (_C_BP_Group_ID == 0) { MBPartner bp = new MBPartner(GetCtx(), _C_BPartner_ID, Get_Trx()); if (bp.Get_ID() == 0) { throw new Exception("Business Partner not found - C_BPartner_ID=" + _C_BPartner_ID); } CheckBP(bp); } else { String sql = "SELECT * FROM C_BPartner WHERE C_BP_Group_ID=@Param1 AND IsActive='Y'"; SqlParameter[] Param = new SqlParameter[1]; DataTable dt = null; IDataReader idr = null; try { Param[0] = new SqlParameter("@Param1", _C_BP_Group_ID); idr = DataBase.DB.ExecuteReader(sql, Param, Get_Trx()); dt = new DataTable(); dt.Load(idr); idr.Close(); foreach (DataRow dr in dt.Rows) { MBPartner bp = new MBPartner(GetCtx(), dr, Get_Trx()); CheckBP(bp); } } catch (Exception e) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, sql, e); } finally { dt = null; if (idr != null) { idr.Close(); } } } return("OK"); }
} // invoiceDone /// <summary> /// New Invoice /// </summary> /// <param name="request">request</param> private void InvoiceNew(MRequest request) { _m_invoice = new MInvoice(GetCtx(), 0, Get_TrxName()); _m_invoice.SetC_DocTypeTarget_ID(MDocBaseType.DOCBASETYPE_ARINVOICE); MBPartner partner = new MBPartner(GetCtx(), request.GetC_BPartner_ID(), Get_TrxName()); _m_invoice.SetBPartner(partner); _m_invoice.SetM_PriceList_ID(partner.GetM_PriceList_ID()); int _CountVA009 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA009_' AND IsActive = 'Y'")); if (_CountVA009 > 0) { _m_invoice.SetVA009_PaymentMethod_ID(partner.GetVA009_PaymentMethod_ID()); } _m_invoice.Save(); request.SetC_Invoice_ID(_m_invoice.GetC_Invoice_ID()); request.Save(); if (string.IsNullOrEmpty(_msg)) { _msg = "Invoice-[ID:" + _m_invoice.Get_ID() + "] created"; } else { _msg += ",Invoice-[ID: " + _m_invoice.Get_ID() + "] created"; } //_m_linecount = 0; } // invoiceNew
public Dictionary <String, String> GetBPartner(Ctx ctx, string fields) { string[] paramValue = fields.Split(','); int C_BPartner_ID; //Assign parameter value C_BPartner_ID = Util.GetValueOfInt(paramValue[0].ToString()); MBPartner bpartner = new MBPartner(ctx, C_BPartner_ID, null); Dictionary <String, String> retDic = new Dictionary <string, string>(); retDic["M_ReturnPolicy_ID"] = bpartner.GetM_ReturnPolicy_ID().ToString(); retDic["M_ReturnPolicy_ID"] = bpartner.GetPO_ReturnPolicy_ID().ToString(); return(retDic); }
/// <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
// Added by Bharat on 16/May/2017 public Dictionary <string, object> GetBPDocTypeData(Ctx ctx, string fields) { int C_BPartner_ID = Util.GetValueOfInt(fields); Dictionary <string, object> retDic = new Dictionary <string, object>(); MBPartner bp = new MBPartner(ctx, C_BPartner_ID, null); retDic["C_PaymentTerm_ID"] = bp.GetC_PaymentTerm_ID(); retDic["PaymentRule"] = bp.GetPaymentRule(); retDic["InvoiceRule"] = bp.GetInvoiceRule(); retDic["DeliveryRule"] = bp.GetDeliveryRule(); retDic["FreightCostRule"] = bp.GetFreightCostRule(); retDic["PaymentRulePO"] = bp.GetPaymentRulePO(); retDic["DeliveryViaRule"] = bp.GetDeliveryViaRule(); retDic["PO_PaymentTerm_ID"] = bp.GetPO_PaymentTerm_ID(); return(retDic); }
/// <summary> /// Check BP /// </summary> /// <param name="bp">bp bp</param> private void CheckBP(MBPartner bp) { AddLog(0, null, null, bp.GetName() + ":"); // See also VMerge.postMerge CheckPayments(bp); CheckInvoices(bp); // bp.SetTotalOpenBalance(); bp.SetActualLifeTimeValue(); bp.Save(); // // if (bp.getSO_CreditUsed().signum() != 0) AddLog(0, null, bp.GetSO_CreditUsed(), Msg.GetElement(GetCtx(), "SO_CreditUsed")); AddLog(0, null, bp.GetTotalOpenBalance(), Msg.GetElement(GetCtx(), "TotalOpenBalance")); AddLog(0, null, bp.GetActualLifeTimeValue(), Msg.GetElement(GetCtx(), "ActualLifeTimeValue")); // Commit(); } // checkBP
} // invoiceDone /// <summary> /// New Invoice /// </summary> /// <param name="request">request</param> private void InvoiceNew(MRequest request) { _m_invoice = new MInvoice(GetCtx(), 0, Get_TrxName()); _m_invoice.SetC_DocTypeTarget_ID(MDocBaseType.DOCBASETYPE_ARINVOICE); MBPartner partner = new MBPartner(GetCtx(), request.GetC_BPartner_ID(), null); _m_invoice.SetBPartner(partner); _m_invoice.Save(); if (string.IsNullOrEmpty(_msg)) { _msg = "Invoice-[ID:" + _m_invoice.Get_ID() + "] created"; } else { _msg += ",Invoice-[ID: " + _m_invoice.Get_ID() + "] created"; } _m_linecount = 0; } // invoiceNew
} // checkPayments /// <summary> /// Check Invoices /// </summary> /// <param name="bp">bp business partner</param> private void CheckInvoices(MBPartner bp) { // See also VMerge.postMerge int changed = 0; MInvoice[] invoices = MInvoice.GetOfBPartner(GetCtx(), bp.GetC_BPartner_ID(), Get_Trx()); for (int i = 0; i < invoices.Length; i++) { MInvoice invoice = invoices[i]; if (invoice.TestAllocation()) { invoice.Save(); changed++; } } if (changed != 0) { AddLog(0, null, new Decimal(invoices.Length), Msg.GetElement(GetCtx(), "C_Invoice_ID") + " - #" + changed); } } // checkInvoices
} // checkBP /// <summary> /// Check Payments /// </summary> /// <param name="bp">bp business partner</param> private void CheckPayments(MBPartner bp) { // See also VMerge.postMerge int changed = 0; MPayment[] payments = MPayment.GetOfBPartner(GetCtx(), bp.GetC_BPartner_ID(), Get_Trx()); for (int i = 0; i < payments.Length; i++) { MPayment payment = payments[i]; if (payment.TestAllocation()) { payment.Save(); changed++; } } if (changed != 0) { AddLog(0, null, new Decimal(payments.Length), Msg.GetElement(GetCtx(), "C_Payment_ID") + " - #" + changed); } } // checkPayments
/// <summary> /// Create new Order /// </summary> /// <param name="rLine">request line</param> private void NewOrder(MRequisitionLine rLine, int C_BPartner_ID) { if (_order != null) { CloseOrder(); } // BPartner if (_m_bpartner == null || C_BPartner_ID != _m_bpartner.GetC_BPartner_ID()) { _m_bpartner = new MBPartner(GetCtx(), C_BPartner_ID, null); } // Order _order = new MOrder(GetCtx(), 0, Get_TrxName()); _order.SetIsSOTrx(false); _order.SetC_DocTypeTarget_ID(); _order.SetBPartner(_m_bpartner); // default po document type if (!_ConsolidateDocument) { _order.SetDescription(Msg.GetElement(GetCtx(), "M_Requisition_ID") + ": " + rLine.GetParent().GetDocumentNo()); } // Prepare Save _m_M_Requisition_ID = rLine.GetM_Requisition_ID(); if (!_order.Save()) { throw new Exception("Cannot save Order"); } else { if (String.IsNullOrEmpty(createdPO)) { createdPO = _order.GetDocumentNo(); } else { createdPO += " , " + _order.GetDocumentNo(); } } }
} // mergeTable /// <summary> /// Post Merge /// </summary> /// <param name="ColumnName">column name</param> /// <param name="to_ID">ID</param> private void PostMerge(String ColumnName, int to_ID) { if (ColumnName.Equals(AD_ORG_ID)) { } else if (ColumnName.Equals(AD_USER_ID)) { } else if (ColumnName.Equals(C_BPARTNER_ID)) { MBPartner bp = new MBPartner(GetCtx(), to_ID, Get_TrxName()); if (bp.Get_ID() != 0) { MPayment[] payments = MPayment.GetOfBPartner(GetCtx(), bp.GetC_BPartner_ID(), Get_TrxName()); for (int i = 0; i < payments.Length; i++) { MPayment payment = payments[i]; if (payment.TestAllocation()) { payment.Save(); } } MInvoice[] invoices = MInvoice.GetOfBPartner(GetCtx(), bp.GetC_BPartner_ID(), Get_TrxName()); for (int i = 0; i < invoices.Length; i++) { MInvoice invoice = invoices[i]; if (invoice.TestAllocation()) { invoice.Save(); } } bp.SetTotalOpenBalance(); bp.SetActualLifeTimeValue(); bp.Save(); } } else if (ColumnName.Equals(M_PRODUCT_ID)) { } } // postMerge
public JsonResult GetBPartner(string param) { string retError = ""; string retJSON = ""; if (Session["ctx"] != null) { VAdvantage.Utility.Ctx ctx = Session["ctx"] as Ctx; string[] paramValue = param.Split(','); int C_BPartner_ID; //Assign parameter value C_BPartner_ID = Util.GetValueOfInt(paramValue[0].ToString()); MBPartner bpartner = new MBPartner(ctx, C_BPartner_ID, null); Dictionary <String, String> retDic = new Dictionary <string, string>(); // Reset Orig Shipment retDic["M_ReturnPolicy_ID"] = bpartner.GetM_ReturnPolicy_ID().ToString(); retDic["M_ReturnPolicy_ID"] = bpartner.GetPO_ReturnPolicy_ID().ToString(); //retDic["DateOrdered", order.GetDateOrdered()); retJSON = JsonConvert.SerializeObject(retDic); } else { retError = "Session Expired"; } return(Json(new { result = retJSON, error = retError }, JsonRequestBehavior.AllowGet)); }
/// <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 Dictionary <String, String> GetBPartner(Ctx ctx, string fields) { string[] paramValue = fields.Split(','); int C_BPartner_ID; //Assign parameter value C_BPartner_ID = Util.GetValueOfInt(paramValue[0].ToString()); MBPartner bpartner = new MBPartner(ctx, C_BPartner_ID, null); Dictionary <String, String> retDic = new Dictionary <string, string>(); retDic["M_ReturnPolicy_ID"] = bpartner.GetM_ReturnPolicy_ID().ToString(); retDic["PO_ReturnPolicy_ID"] = bpartner.GetPO_ReturnPolicy_ID().ToString(); // Added By Amit if (bpartner.GetM_DiscountSchema_ID() != 0) { retDic["M_DiscountSchema_ID"] = bpartner.GetM_DiscountSchema_ID().ToString(); } else { retDic["M_DiscountSchema_ID"] = "0"; } if (bpartner.GetC_BP_Group_ID() > 0) { retDic["C_BP_Group_ID"] = bpartner.GetC_BP_Group_ID().ToString(); } else { retDic["C_BP_Group_ID"] = "0"; } if (bpartner.GetFlatDiscount() > 0) { retDic["FlatDiscount"] = bpartner.GetFlatDiscount().ToString(); } else { retDic["FlatDiscount"] = "0"; } //30-4-2016 //VA025 //if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE ISACTIVE = 'Y' AND PREFIX='VA025_'")) > 0) //{ // if (bpartner.GetVA025_DiscountCalculation() != null) // { // retDic["VA025_DiscountCalculation"] = bpartner.GetVA025_DiscountCalculation().ToString(); // } // else // { // retDic["VA025_DiscountCalculation"] = null; // } // if (bpartner.GetVA025_PromotionalDiscount() != 0) // { // retDic["VA025_PromotionalDiscount"] = bpartner.GetVA025_PromotionalDiscount().ToString(); // } // else // { // retDic["VA025_PromotionalDiscount"] = "0"; // } //} //Amit return(retDic); }
/** * Generate Shipments * @param pstmt order query * @return info */ private String Generate(IDataReader idr) { DataTable dt = new DataTable(); try { dt.Load(idr); idr.Close(); foreach (DataRow dr in dt.Rows)// while (dr.next ()) { MOrder order = new MOrder(GetCtx(), dr, Get_TrxName()); // New Invoice Location if (!_ConsolidateDocument || (_invoice != null && (_invoice.GetC_BPartner_Location_ID() != order.GetBill_Location_ID() || _invoice.GetC_PaymentTerm_ID() != order.GetC_PaymentTerm_ID()))) { CompleteInvoice(); } bool completeOrder = MOrder.INVOICERULE_AfterOrderDelivered.Equals(order.GetInvoiceRule()); // Schedule After Delivery bool doInvoice = false; if (MOrder.INVOICERULE_CustomerScheduleAfterDelivery.Equals(order.GetInvoiceRule())) { _bp = new MBPartner(GetCtx(), order.GetBill_BPartner_ID(), null); if (_bp.GetC_InvoiceSchedule_ID() == 0) { log.Warning("BPartner has no Schedule - set to After Delivery"); order.SetInvoiceRule(MOrder.INVOICERULE_AfterDelivery); order.Save(); } else { MInvoiceSchedule ins = MInvoiceSchedule.Get(GetCtx(), _bp.GetC_InvoiceSchedule_ID(), Get_TrxName()); if (ins.CanInvoice(order.GetDateOrdered(), order.GetGrandTotal())) { doInvoice = true; } else { continue; } } } // Schedule // After Delivery if (doInvoice || MOrder.INVOICERULE_AfterDelivery.Equals(order.GetInvoiceRule())) { MInOut shipment = null; MInOutLine[] shipmentLines = order.GetShipmentLines(); for (int i = 0; i < shipmentLines.Length; i++) { MInOutLine shipLine = shipmentLines[i]; if (shipLine.IsInvoiced()) { continue; } if (shipment == null || shipment.GetM_InOut_ID() != shipLine.GetM_InOut_ID()) { shipment = new MInOut(GetCtx(), shipLine.GetM_InOut_ID(), Get_TrxName()); } if (!shipment.IsComplete() || // ignore incomplete or reversals shipment.GetDocStatus().Equals(MInOut.DOCSTATUS_Reversed)) { continue; } // CreateLine(order, shipment, shipLine); } // shipment lines _line += 1000; } // After Order Delivered, Immediate else { MOrderLine[] oLines = order.GetLines(true, null); for (int i = 0; i < oLines.Length; i++) { MOrderLine oLine = oLines[i]; Decimal toInvoice = Decimal.Subtract(oLine.GetQtyOrdered(), oLine.GetQtyInvoiced()); if (toInvoice.CompareTo(Env.ZERO) == 0 && oLine.GetM_Product_ID() != 0) { continue; } // bool fullyDelivered = oLine.GetQtyOrdered().CompareTo(oLine.GetQtyDelivered()) == 0; // Complete Order if (completeOrder && !fullyDelivered) { log.Fine("Failed CompleteOrder - " + oLine); completeOrder = false; break; } // Immediate else if (MOrder.INVOICERULE_Immediate.Equals(order.GetInvoiceRule())) { log.Fine("Immediate - ToInvoice=" + toInvoice + " - " + oLine); Decimal qtyEntered = toInvoice; // Correct UOM for QtyEntered if (oLine.GetQtyEntered().CompareTo(oLine.GetQtyOrdered()) != 0) { qtyEntered = Decimal.Round(Decimal.Divide(Decimal.Multiply( toInvoice, oLine.GetQtyEntered()), oLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero); } // if (oLine.IsContract() == false) { CreateLine(order, oLine, toInvoice, qtyEntered); log.Info("ID " + oLine.Get_ID() + "Qty Ordered " + oLine.GetQtyOrdered() + " Qty Invoiced " + oLine.GetQtyInvoiced()); } } else { log.Fine("Failed: " + order.GetInvoiceRule() + " - ToInvoice=" + toInvoice + " - " + oLine); } } // for all order lines if (MOrder.INVOICERULE_Immediate.Equals(order.GetInvoiceRule())) { _line += 1000; } } // Complete Order successful if (completeOrder && MOrder.INVOICERULE_AfterOrderDelivered.Equals(order.GetInvoiceRule())) { MInOut[] shipments = order.GetShipments(true); for (int i = 0; i < shipments.Length; i++) { MInOut ship = shipments[i]; if (!ship.IsComplete() || // ignore incomplete or reversals ship.GetDocStatus().Equals(MInOut.DOCSTATUS_Reversed)) { continue; } MInOutLine[] shipLines = ship.GetLines(false); for (int j = 0; j < shipLines.Length; j++) { MInOutLine shipLine = shipLines[j]; if (!order.IsOrderLine(shipLine.GetC_OrderLine_ID())) { continue; } if (!shipLine.IsInvoiced()) { CreateLine(order, ship, shipLine); } } // lines _line += 1000; } // all shipments } // complete Order } // for all orders } catch (Exception e) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, "", e); } finally { if (idr != null) { idr.Close(); } dt = null; } CompleteInvoice(); return("@Created@ = " + _created); }
/// <summary> /// Process /// </summary> /// <returns>info</returns> protected override String DoIt() { log.Info("C_DunningRun_ID=" + _C_DunningRun_ID + ",R_MailText_ID=" + _R_MailText_ID + ", EmailPDF=" + _EMailPDF + ",IsOnlyIfBPBalance=" + _IsOnlyIfBPBalance); // Need to have Template if (_EMailPDF && _R_MailText_ID == 0) { throw new Exception("@NotFound@: @R_MailText_ID@"); } String subject = ""; MMailText mText = null; if (_EMailPDF) { mText = new MMailText(GetCtx(), _R_MailText_ID, Get_TrxName()); if (_EMailPDF && mText.Get_ID() == 0) { throw new Exception("@NotFound@: @R_MailText_ID@ - " + _R_MailText_ID); } subject = mText.GetMailHeader(); } // MDunningRun run = new MDunningRun(GetCtx(), _C_DunningRun_ID, Get_TrxName()); if (run.Get_ID() == 0) { throw new Exception("@NotFound@: @C_DunningRun_ID@ - " + _C_DunningRun_ID); } // Print Format on Dunning Level MDunningLevel level = new MDunningLevel(GetCtx(), run.GetC_DunningLevel_ID(), Get_TrxName()); //MPrintFormat format = MPrintFormat.Get(GetCtx(), level.GetDunning_PrintFormat_ID(), false); MClient client = MClient.Get(GetCtx()); int count = 0; int errors = 0; MDunningRunEntry[] entries = run.GetEntries(false); for (int i = 0; i < entries.Length; i++) { MDunningRunEntry entry = entries[i]; if (_IsOnlyIfBPBalance && Env.Signum(entry.GetAmt()) <= 0) { continue; } // To BPartner MBPartner bp = new MBPartner(GetCtx(), entry.GetC_BPartner_ID(), Get_TrxName()); if (bp.Get_ID() == 0) { AddLog(entry.Get_ID(), null, null, "@NotFound@: @C_BPartner_ID@ " + entry.GetC_BPartner_ID()); errors++; continue; } // To User MUser to = new MUser(GetCtx(), entry.GetAD_User_ID(), Get_TrxName()); if (_EMailPDF) { if (to.Get_ID() == 0) { AddLog(entry.Get_ID(), null, null, "@NotFound@: @AD_User_ID@ - " + bp.GetName()); errors++; continue; } else if (to.GetEMail() == null || to.GetEMail().Length == 0) { AddLog(entry.Get_ID(), null, null, "@NotFound@: @EMail@ - " + to.GetName()); errors++; continue; } } // BP Language //Language language =Language.getLoginLanguage(); // Base Language Language language = Env.GetLoginLanguage(GetCtx()); String tableName = "C_Dunning_Header_v"; if (client.IsMultiLingualDocument()) { tableName += "t"; String AD_Language = bp.GetAD_Language(); if (AD_Language != null) { //language =language.getLanguage(AD_Language); } } // format.SetLanguage(language); // format.SetTranslationLanguage(language); // query Query query = new Query(tableName); query.AddRestriction("C_DunningRunEntry_ID", Query.EQUAL, entry.GetC_DunningRunEntry_ID()); // Engine //PrintInfo info = new PrintInfo( // bp.GetName(), // X_C_DunningRunEntry.Table_ID, // entry.GetC_DunningRunEntry_ID(), // entry.GetC_BPartner_ID()); //info.SetDescription(bp.GetName() + ", Amt=" + entry.GetAmt()); //ReportEngine re = new ReportEngine(GetCtx(), format, query, info); bool printed = false; if (_EMailPDF) { EMail email = client.CreateEMail(to.GetEMail(), to.GetName(), null, null); if (email == null || !email.IsValid()) { AddLog(entry.Get_ID(), null, null, "@RequestActionEMailError@ Invalid EMail: " + to); errors++; continue; } mText.SetUser(to); // variable context mText.SetBPartner(bp); mText.SetPO(entry); String message = mText.GetMailText(true); if (mText.IsHtml()) { email.SetMessageHTML(mText.GetMailHeader(), message); } else { email.SetSubject(mText.GetMailHeader()); email.SetMessageText(message); } // //File attachment = re.GetPDF(File.createTempFile("Dunning", ".pdf")); //log.Fine(to + " - " + attachment); //email.AddAttachment(attachment); // String msg = email.Send(); MUserMail um = new MUserMail(mText, entry.GetAD_User_ID(), email); um.Save(); if (msg.Equals(EMail.SENT_OK)) { AddLog(entry.Get_ID(), null, null, bp.GetName() + " @RequestActionEMailOK@"); count++; printed = true; } else { AddLog(entry.Get_ID(), null, null, bp.GetName() + " @RequestActionEMailError@ " + msg); errors++; } } else { //re.print(); count++; printed = true; } if (printed) { entry.SetProcessed(true); entry.Save(); DunningLevelConsequences(level, entry); } } // for all dunning letters if (errors == 0) { run.SetProcessed(true); run.Save(); } if (_EMailPDF) { return("@Sent@=" + count + " - @Errors@=" + errors); } return("@Printed@=" + count); }
/// <summary> /// Process. /// A Sales Order is created for the entered Business Partner. /// A sales order line is created for each RfQ line quantity, /// where "Offer Quantity" is selected. /// If on the RfQ Line Quantity, an offer amount is entered (not 0), /// that price is used. /// If a magin is entered on RfQ Line Quantity, it overwrites the /// general margin. The margin is the percentage added to the /// Best Response Amount. /// </summary> /// <returns>message</returns> protected override String DoIt() { MRfQ rfq = new MRfQ(GetCtx(), _C_RfQ_ID, Get_TrxName()); if (rfq.Get_ID() == 0) { throw new ArgumentException("No RfQ found"); } log.Info("doIt - " + rfq); if (rfq.GetC_BPartner_ID() == 0 || rfq.GetC_BPartner_Location_ID() == 0) { throw new Exception("No Business Partner/Location"); } MBPartner bp = new MBPartner(GetCtx(), rfq.GetC_BPartner_ID(), Get_TrxName()); MOrder order = new MOrder(GetCtx(), 0, Get_TrxName()); order.SetIsSOTrx(true); if (_C_DocType_ID != 0) { order.SetC_DocTypeTarget_ID(_C_DocType_ID); } else { order.SetC_DocTypeTarget_ID(); } order.SetBPartner(bp); order.SetC_BPartner_Location_ID(rfq.GetC_BPartner_Location_ID()); order.SetSalesRep_ID(rfq.GetSalesRep_ID()); if (rfq.GetDateWorkComplete() != null) { order.SetDatePromised(rfq.GetDateWorkComplete()); } order.Save(); MRfQLine[] lines = rfq.GetLines(); for (int i = 0; i < lines.Length; i++) { MRfQLine line = lines[i]; MRfQLineQty[] qtys = line.GetQtys(); for (int j = 0; j < qtys.Length; j++) { MRfQLineQty qty = qtys[j]; if (qty.IsActive() && qty.IsOfferQty()) { MOrderLine ol = new MOrderLine(order); ol.SetM_Product_ID(line.GetM_Product_ID(), qty.GetC_UOM_ID()); ol.SetDescription(line.GetDescription()); ol.SetQty(qty.GetQty()); // Decimal price = qty.GetOfferAmt(); if (Env.Signum(price) == 0) { price = qty.GetBestResponseAmt(); if (Env.Signum(price) == 0) { price = Env.ZERO; log.Warning(" - BestResponse=0 - " + qty); } else { Decimal margin = qty.GetMargin(); if (Env.Signum(margin) == 0) { margin = rfq.GetMargin(); } if (Env.Signum(margin) != 0) { margin = Decimal.Add(margin, ONEHUNDRED); price = Decimal.Round(Decimal.Divide(Decimal.Multiply(price, margin), ONEHUNDRED), 2, MidpointRounding.AwayFromZero); } } } // price ol.SetPrice(price); ol.Save(); } // Offer Qty } // All Qtys } // All Lines rfq.SetC_Order_ID(order.GetC_Order_ID()); rfq.Save(); return(order.GetDocumentNo()); }
/// <summary> /// Process. /// Create purchase order(s) for the resonse(s) and lines marked as /// Selected Winner using the selected Purchase Quantity (in RfQ Line Quantity) . /// If a Response is marked as Selected Winner, all lines are created /// (and Selected Winner of other responses ignored). /// If there is no response marked as Selected Winner, the lines are used. /// </summary> /// <returns>message</returns> protected override String DoIt() { MRfQ rfq = new MRfQ(GetCtx(), _C_RfQ_ID, Get_TrxName()); if (rfq.Get_ID() == 0) { throw new ArgumentException("No RfQ found"); } log.Info(rfq.ToString()); // Complete MRfQResponse[] responses = rfq.GetResponses(true, true); log.Config("#Responses=" + responses.Length); if (responses.Length == 0) { throw new ArgumentException("No completed RfQ Responses found"); } // Winner for entire RfQ for (int i = 0; i < responses.Length; i++) { MRfQResponse response = responses[i]; if (!response.IsSelectedWinner()) { continue; } // MBPartner bp = new MBPartner(GetCtx(), response.GetC_BPartner_ID(), Get_TrxName()); log.Config("Winner=" + bp); MOrder order = new MOrder(GetCtx(), 0, Get_TrxName()); order.SetIsSOTrx(false); if (_C_DocType_ID != 0) { order.SetC_DocTypeTarget_ID(_C_DocType_ID); } else { order.SetC_DocTypeTarget_ID(); } order.SetBPartner(bp); order.SetC_BPartner_Location_ID(response.GetC_BPartner_Location_ID()); order.SetSalesRep_ID(rfq.GetSalesRep_ID()); if (response.GetDateWorkComplete() != null) { order.SetDatePromised(response.GetDateWorkComplete()); } else if (rfq.GetDateWorkComplete() != null) { order.SetDatePromised(rfq.GetDateWorkComplete()); } order.Save(); // MRfQResponseLine[] lines = response.GetLines(false); for (int j = 0; j < lines.Length; j++) { // Respones Line MRfQResponseLine line = lines[j]; if (!line.IsActive()) { continue; } MRfQResponseLineQty[] qtys = line.GetQtys(false); // Response Line Qty for (int k = 0; k < qtys.Length; k++) { MRfQResponseLineQty qty = qtys[k]; // Create PO Lline for all Purchase Line Qtys if (qty.GetRfQLineQty().IsActive() && qty.GetRfQLineQty().IsPurchaseQty()) { MOrderLine ol = new MOrderLine(order); ol.SetM_Product_ID(line.GetRfQLine().GetM_Product_ID(), qty.GetRfQLineQty().GetC_UOM_ID()); ol.SetDescription(line.GetDescription()); ol.SetQty(qty.GetRfQLineQty().GetQty()); Decimal?price = qty.GetNetAmt(); ol.SetPrice(price == null?Env.ZERO:price.Value); ol.Save(); } } } response.SetC_Order_ID(order.GetC_Order_ID()); response.Save(); return(order.GetDocumentNo()); } // Selected Winner on Line Level int noOrders = 0; for (int i = 0; i < responses.Length; i++) { MRfQResponse response = responses[i]; MBPartner bp = null; MOrder order = null; // For all Response Lines MRfQResponseLine[] lines = response.GetLines(false); for (int j = 0; j < lines.Length; j++) { MRfQResponseLine line = lines[j]; if (!line.IsActive() || !line.IsSelectedWinner()) { continue; } // New/different BP if (bp == null) { bp = new MBPartner(GetCtx(), response.GetC_BPartner_ID(), Get_TrxName()); order = null; } log.Config("Line=" + line + ", Winner=" + bp); // New Order if (order == null) { order = new MOrder(GetCtx(), 0, Get_TrxName()); order.SetIsSOTrx(false); order.SetC_DocTypeTarget_ID(); order.SetBPartner(bp); order.SetC_BPartner_Location_ID(response.GetC_BPartner_Location_ID()); order.SetSalesRep_ID(rfq.GetSalesRep_ID()); order.Save(); noOrders++; //AddLog(0, null, null, order.GetDocumentNo()); AddLog(0, DateTime.Now, null, order.GetDocumentNo()); } // For all Qtys MRfQResponseLineQty[] qtys = line.GetQtys(false); for (int k = 0; k < qtys.Length; k++) { MRfQResponseLineQty qty = qtys[k]; if (qty.GetRfQLineQty().IsActive() && qty.GetRfQLineQty().IsPurchaseQty()) { MOrderLine ol = new MOrderLine(order); ol.SetM_Product_ID(line.GetRfQLine().GetM_Product_ID(), qty.GetRfQLineQty().GetC_UOM_ID()); ol.SetDescription(line.GetDescription()); ol.SetQty(qty.GetRfQLineQty().GetQty()); Decimal?price = qty.GetNetAmt(); ol.SetPriceActual(price); ol.Save(); } } // for all Qtys } // for all Response Lines if (order != null) { response.SetC_Order_ID(order.GetC_Order_ID()); response.Save(); } } return("#" + noOrders); }
/// <summary> /// Perform Process. /// </summary> /// <returns>Message (variables are parsed)</returns> protected override String DoIt() { log.Info("doIt - C_CommissionRun_ID=" + GetRecord_ID()); // Load Data MCommissionRun comRun = new MCommissionRun(GetCtx(), GetRecord_ID(), Get_Trx()); if (comRun.Get_ID() == 0) { throw new ArgumentException("CommissionAPInvoice - No Commission Run"); } if (Env.ZERO.CompareTo(comRun.GetGrandTotal()) == 0) { throw new ArgumentException("@GrandTotal@ = 0"); } MCommission com = new MCommission(GetCtx(), comRun.GetC_Commission_ID(), Get_Trx()); if (com.Get_ID() == 0) { throw new ArgumentException("CommissionAPInvoice - No Commission"); } if (com.GetC_Charge_ID() == 0) { throw new ArgumentException("CommissionAPInvoice - No Charge on Commission"); } MBPartner bp = new MBPartner(GetCtx(), com.GetC_BPartner_ID(), Get_Trx()); if (bp.Get_ID() == 0) { throw new ArgumentException("CommissionAPInvoice - No BPartner"); } // Create Invoice MInvoice invoice = new MInvoice(GetCtx(), 0, null); invoice.SetClientOrg(com.GetAD_Client_ID(), com.GetAD_Org_ID()); invoice.SetC_DocTypeTarget_ID(MDocBaseType.DOCBASETYPE_APINVOICE); // API invoice.SetBPartner(bp); // invoice.setDocumentNo (comRun.getDocumentNo()); // may cause unique constraint invoice.SetSalesRep_ID(GetAD_User_ID()); // caller // if (com.GetC_Currency_ID() != invoice.GetC_Currency_ID()) { throw new ArgumentException("CommissionAPInvoice - Currency of PO Price List not Commission Currency"); } // if (!invoice.Save()) { throw new Exception("CommissionAPInvoice - cannot save Invoice"); } // Create Invoice Line MInvoiceLine iLine = new MInvoiceLine(invoice); iLine.SetC_Charge_ID(com.GetC_Charge_ID()); iLine.SetQty(1); iLine.SetPrice(comRun.GetGrandTotal()); iLine.SetTax(); if (!iLine.Save()) { throw new Exception("CommissionAPInvoice - cannot save Invoice Line"); } // return("@C_Invoice_ID@ = " + invoice.GetDocumentNo()); }
/// <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); }
/// <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); }
/** * Create Trial Asset * @param ctx context * @param user user * @param entityType entity type * @return asset or null if no product found */ public static MAsset GetTrial(Ctx ctx, MUser user, String entityType) { if (user == null) { _log.Warning("Cannot create Trial - No User"); return(null); } if (Util.IsEmpty(entityType)) { _log.Warning("Cannot create Trial - No Entity Type"); return(null); } MProduct product = MProduct.GetTrial(ctx, entityType); if (product == null) { _log.Warning("No Trial for Entity Type=" + entityType); return(null); } // DateTime now = Convert.ToDateTime(CommonFunctions.CurrentTimeMillis()); // MAsset asset = new MAsset(ctx, 0, null); asset.SetClientOrg(user); asset.SetAssetServiceDate(now); asset.SetIsOwned(false); asset.SetIsTrialPhase(true); // MBPartner partner = new MBPartner(ctx, user.GetC_BPartner_ID(), null); String documentNo = "Trial"; // Value String value = partner.GetValue() + "_" + product.GetValue(); if (value.Length > 40 - documentNo.Length) { value = value.Substring(0, 40 - documentNo.Length) + documentNo; } asset.SetValue(value); // Name MProduct.afterSave String name = "Trial " + partner.GetName() + " - " + product.GetName(); if (name.Length > 60) { name = name.Substring(0, 60); } asset.SetName(name); // Description String description = product.GetDescription(); asset.SetDescription(description); // User asset.SetAD_User_ID(user.GetAD_User_ID()); asset.SetC_BPartner_ID(user.GetC_BPartner_ID()); // Product asset.SetM_Product_ID(product.GetM_Product_ID()); asset.SetA_Asset_Group_ID(product.GetA_Asset_Group_ID()); asset.SetQty(new Decimal(product.GetSupportUnits())); // Guarantee & Version asset.SetGuaranteeDate(TimeUtil.AddDays(now, product.GetTrialPhaseDays())); asset.SetVersionNo(product.GetVersionNo()); // return(asset); }
} // prepare /// <summary> /// Perform Process. /// </summary> /// <returns>Message (clear text)</returns> protected override String DoIt() { int index = 1; StringBuilder sql = new StringBuilder("SELECT * " + "FROM S_TimeExpense e " + "WHERE e.Processed='Y'" + " AND e.AD_Client_ID=@param1"); // #1 if (_C_BPartner_ID != 0 && _C_BPartner_ID != -1) { index++; sql.Append(" AND e.C_BPartner_ID=@param2"); // #2 } if (_DateFrom != null) { index++; sql.Append(" AND e.DateReport >=@param3"); // #3 } if (_DateTo != null) { index++; sql.Append(" AND e.DateReport <=@param4"); // #4 } // JID_0868 // chanegs done by Bharat on 12 September 2018 to handle the case if invoice is created with an expense for the selected Business Partner sql.Append(" AND EXISTS (SELECT * FROM S_TimeExpenseLine el " + "WHERE e.S_TimeExpense_ID=el.S_TimeExpense_ID" + " AND el.C_InvoiceLine_ID IS NULL" + " AND el.ConvertedAmt<>0) " + "ORDER BY e.C_BPartner_ID, e.S_TimeExpense_ID"); // int old_BPartner_ID = -1; MInvoice invoice = null; MTimeExpense te = null; // //PreparedStatement pstmt = null; SqlParameter[] param = new SqlParameter[index]; IDataReader idr = null; DataTable dt = null; try { //pstmt = DataBase.prepareStatement (sql.toString (), get_TrxName()); int par = 0; //pstmt.setInt(par++, getAD_Client_ID()); param[0] = new SqlParameter("@param1", GetAD_Client_ID()); if (_C_BPartner_ID != 0 && _C_BPartner_ID != -1) { par++; //pstmt.setInt (par++, _C_BPartner_ID); param[par] = new SqlParameter("@param2", _C_BPartner_ID); } if (_DateFrom != null) { par++; //pstmt.setTimestamp (par++, _DateFrom); param[par] = new SqlParameter("@param3", _DateFrom); } if (_DateTo != null) { par++; //pstmt.setTimestamp (par++, _DateTo); param[par] = new SqlParameter("@param4", _DateTo); } //ResultSet rs = pstmt.executeQuery (); idr = DataBase.DB.ExecuteReader(sql.ToString(), param, Get_TrxName()); dt = new DataTable(); dt.Load(idr); idr.Close(); if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) // ********* Expense Line Loop { te = new MTimeExpense(GetCtx(), dr, Get_TrxName()); // New BPartner - New Order // if (te.GetC_BPartner_ID() != old_BPartner_ID) { CompleteInvoice(invoice, te); MBPartner bp = new MBPartner(GetCtx(), te.GetC_BPartner_ID(), Get_TrxName()); log.Info("New Invoice for " + bp); invoice = new MInvoice(GetCtx(), 0, Get_TrxName()); invoice.SetBPartner(bp); if (invoice.GetC_BPartner_Location_ID() == 0) { log.Log(Level.SEVERE, "No BP Location: " + bp); AddLog(0, te.GetDateReport(), null, "No Location: " + te.GetDocumentNo() + " " + bp.GetName()); invoice = null; break; } // Siddheshwar: added a code to check for payment method if null if (bp.GetVA009_PO_PaymentMethod_ID() <= 0) { paymethod = GetPaymentMethod(te); if (paymethod <= 0) { if (!noPayMethEmp.Contains(bp.GetC_BPartner_ID())) { noPayMethEmp.Add(bp.GetC_BPartner_ID()); if (string.IsNullOrEmpty(bpNameNoPM)) { bpNameNoPM = bp.GetName(); } else { bpNameNoPM += bp.GetName() + ", "; } return(Msg.GetMsg(GetCtx(), "NoPayMethEmp") + bpNameNoPM); } } else { invoice.SetVA009_PaymentMethod_ID(paymethod); } } else { //JID_1783_1 if active paymentMethod not found ,then dont create the invoice. if (Util.GetValueOfString(DB.ExecuteScalar("SELECT IsActive FROM VA009_PaymentMethod WHERE VA009_PaymentMethod_ID=" + bp.GetVA009_PO_PaymentMethod_ID(), null, Get_Trx())).Equals("Y")) { invoice.SetVA009_PaymentMethod_ID(bp.GetVA009_PO_PaymentMethod_ID()); } else { return(Msg.GetMsg(GetCtx(), "IsActivePaymentMethodInv"));; } } // Checking payment term if (bp.GetPO_PaymentTerm_ID() <= 0) { payterm = GetPaymentTerm(te); if (payterm <= 0) { if (!PayTermEmp.Contains(bp.GetC_BPartner_ID())) { PayTermEmp.Add(bp.GetC_BPartner_ID()); if (string.IsNullOrEmpty(bpNamePT)) { bpNamePT = bp.GetName(); } else { bpNamePT += bp.GetName() + ", "; } return(Msg.GetMsg(GetCtx(), "NoPayTerm") + bpNamePT); } } else { invoice.SetC_PaymentTerm_ID(payterm); } } else { //JID_1783_1 if active paymentTerm not found ,then dont create the invoice. if (Util.GetValueOfString(DB.ExecuteScalar("SELECT IsActive FROM C_PaymentTerm WHERE C_PaymentTerm_ID=" + bp.GetPO_PaymentTerm_ID(), null, Get_Trx())).Equals("Y")) { invoice.SetC_PaymentTerm_ID(bp.GetPO_PaymentTerm_ID()); } else { return(Msg.GetMsg(GetCtx(), "IsActivePaymentTermInv")); } } invoice.SetIsExpenseInvoice(true); //added by arpit asked by Surya Sir on DEC 28,2015 invoice.SetClientOrg(te.GetAD_Client_ID(), te.GetAD_Org_ID()); //invoice.SetVA009_PaymentMethod_ID(bp.GetVA009_PO_PaymentMethod_ID()); // JID_0868 // chanegs done by Bharat on 12 September 2018 to set the document type where Expense Invoice checkbox is true. // String qry = "SELECT C_DocType_ID FROM C_DocType " //+ "WHERE AD_Client_ID=@param1 AND DocBaseType=@param2" //+ " AND IsActive='Y' AND IsExpenseInvoice = 'Y' " //+ "ORDER BY C_DocType_ID DESC , IsDefault DESC"; String qry = "SELECT C_DocType_ID FROM C_DocType " + "WHERE AD_Client_ID=" + GetAD_Client_ID() + @" AND DocBaseType='" + MDocBaseType.DOCBASETYPE_APINVOICE + @"'" + " AND IsActive='Y' AND IsExpenseInvoice = 'Y' AND AD_Org_ID IN(0," + te.GetAD_Org_ID() + ") " + " ORDER BY AD_Org_ID Desc, C_DocType_ID DESC , IsDefault DESC"; //int C_DocType_ID = DB.GetSQLValue(null, qry, GetAD_Client_ID(), MDocBaseType.DOCBASETYPE_APINVOICE); int C_DocType_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry)); if (C_DocType_ID <= 0) { log.Log(Level.SEVERE, "Not found for AC_Client_ID=" + GetAD_Client_ID() + " - " + MDocBaseType.DOCBASETYPE_APINVOICE); return(Msg.GetMsg(GetCtx(), "NoDocTypeExpInvoice")); } else { log.Fine(MDocBaseType.DOCBASETYPE_APINVOICE); } invoice.SetC_DocTypeTarget_ID(C_DocType_ID); //invoice.SetC_DocTypeTarget_ID(MDocBaseType.DOCBASETYPE_APINVOICE); // API //commented by Arpit on Jan 4,2015 Mentis issue no. 0000310 //invoice.SetDocumentNo(te.GetDocumentNo()); // invoice.SetM_PriceList_ID(te.GetM_PriceList_ID()); invoice.SetSalesRep_ID(te.GetDoc_User_ID()); String descr = Msg.Translate(GetCtx(), "S_TimeExpense_ID") + ": " + te.GetDocumentNo() + " " + DisplayType.GetDateFormat(DisplayType.Date).Format(te.GetDateReport()); invoice.SetDescription(descr); if (!invoice.Save()) { return(GetRetrievedError(invoice, "Cannot save Invoice")); // new Exception("Cannot save Invoice"); } //added by arpit asked by Surya Sir on 29/12/2015******* else { old_BPartner_ID = bp.GetC_BPartner_ID(); } //end*************** } // JID_0868 //Description include all document numbers which is come from Time And Expense Recording window to expense invoice in case of multiple records else if (old_BPartner_ID > 0) { String descr = invoice.GetDescription() + "\n" + Msg.Translate(GetCtx(), "S_TimeExpense_ID") + ": " + te.GetDocumentNo() + " " + DisplayType.GetDateFormat(DisplayType.Date).Format(te.GetDateReport()); invoice.SetDescription(descr); } MTimeExpenseLine[] tel = te.GetLines(false); for (int i = 0; i < tel.Length; i++) { MTimeExpenseLine line = tel[i]; // Already Invoiced or nothing to be reimbursed if (line.GetC_InvoiceLine_ID() != 0 || Env.ZERO.CompareTo(line.GetQtyReimbursed()) == 0 || Env.ZERO.CompareTo(line.GetPriceReimbursed()) == 0) { continue; } // Update Header info if (line.GetC_Activity_ID() != 0 && line.GetC_Activity_ID() != invoice.GetC_Activity_ID()) { invoice.SetC_Activity_ID(line.GetC_Activity_ID()); } if (line.GetC_Campaign_ID() != 0 && line.GetC_Campaign_ID() != invoice.GetC_Campaign_ID()) { invoice.SetC_Campaign_ID(line.GetC_Campaign_ID()); } if (line.GetC_Project_ID() != 0 && line.GetC_Project_ID() != invoice.GetC_Project_ID()) { invoice.SetC_Project_ID(line.GetC_Project_ID()); } if (!invoice.Save()) { return(GetRetrievedError(invoice, "Cannot save Invoice")); //new Exception("Cannot save Invoice"); } // Create OrderLine MInvoiceLine il = new MInvoiceLine(invoice); // if (line.GetM_Product_ID() != 0) { il.SetM_Product_ID(line.GetM_Product_ID(), true); } //added by arpit asked by Surya Sir on 28/12/2015_____*************************** if (line.GetC_Charge_ID() != 0) { il.SetC_Charge_ID(line.GetC_Charge_ID()); } //end here ***************************** il.SetQty(line.GetQtyReimbursed()); // Entered/Invoiced il.SetDescription(line.GetDescription()); // il.SetC_Project_ID(line.GetC_Project_ID()); il.SetC_ProjectPhase_ID(line.GetC_ProjectPhase_ID()); il.SetC_ProjectTask_ID(line.GetC_ProjectTask_ID()); il.SetC_Activity_ID(line.GetC_Activity_ID()); il.SetC_Campaign_ID(line.GetC_Campaign_ID()); // // il.setPrice(); // not really a list/limit price for reimbursements il.SetPrice(line.GetPriceReimbursed()); // il.SetC_UOM_ID(line.GetC_UOM_ID()); // JID_0868 // chanegs done by Bharat on 12 September 2018 to set the Amount in List price column. il.SetPriceList(line.GetPriceReimbursed()); il.SetTax(); if (!il.Save()) { return(GetRetrievedError(il, "Cannot save Invoice")); //new Exception("Cannot save Invoice Line"); } // Update TEL line.SetC_InvoiceLine_ID(il.GetC_InvoiceLine_ID()); line.SetIsInvoiced(true); line.Save(); } // for all expense lines } } else { message = Msg.GetMsg(GetCtx(), "NoRecForInv"); } // ********* Expense Line Loop dt = null; //dt.Clear(); } catch (Exception e) { if (dt != null) { dt = null; } if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, sql.ToString(), e); } finally { if (dt != null) { dt = null; } if (idr != null) { idr.Close(); } } CompleteInvoice(invoice, te); //if (_noInvoices == 0) //{ // message = " @No Record Found for Invoice Creation@"; //} //Code for Showing Message when PaymentTerm is null if (!string.IsNullOrEmpty(bpNamePT)) { message += Msg.GetMsg(GetCtx(), "NoPayTerm") + bpNamePT + "\n"; } //code for showing Error Message when Invoice is not completed if (!string.IsNullOrEmpty(bpNameInvoice)) { message += Msg.GetMsg(GetCtx(), "NoInvoiceCreated") + bpNameInvoice + "\n"; } if (!string.IsNullOrEmpty(bpNameNoPM)) { message = Msg.GetMsg(GetCtx(), "NoPayMethEmp") + bpNameNoPM + "\n"; } if (_noInvoices > 0) { message += "" + _noInvoices + " " + Msg.GetMsg(GetCtx(), "VIS_InvGenerated"); } //return "" + _noInvoices + " @Invoices Generated Successfully@"; return(message); } // doIt
/// <summary> /// /// </summary> /// <returns></returns> protected override string DoIt() { int C_Contract_ID = Util.GetValueOfInt(GetRecord_ID()); if (C_Contract_ID != 0) { cont = new VAdvantage.Model.X_C_Contract(GetCtx(), C_Contract_ID, Get_TrxName()); bp = new MBPartner(GetCtx(), cont.GetC_BPartner_ID(), Get_TrxName()); string date = System.DateTime.Now.ToString("dd-MMM-yyyy"); int[] contSch = VAdvantage.Model.X_C_ContractSchedule.GetAllIDs("C_ContractSchedule", "C_Contract_ID = " + C_Contract_ID + " AND FROMDATE <= '" + date + "' AND NVL(C_INVOICE_ID,0) = 0", Get_TrxName()); //Neha----If Not found any Invoice Schedule against the Contract then it will display the error message--11 Sep,2018 if (contSch != null && contSch.Length > 0) { for (int i = 0; i < contSch.Length; i++) { contSchedule = new VAdvantage.Model.X_C_ContractSchedule(GetCtx(), Util.GetValueOfInt(contSch[i]), Get_TrxName()); GenerateInvoice(contSchedule); } } else { return(Msg.GetMsg(GetCtx(), "VIS_NotFoundInvSchedule.")); } sql.Clear(); sql.Append("SELECT COUNT(C_ContractSchedule_ID) FROM C_ContractSchedule WHERE C_Contract_ID = " + C_Contract_ID + " AND NVL(C_INVOICE_ID,0) > 0"); string sql1 = "UPDATE C_Contract SET InvoicesGenerated = " + Util.GetValueOfInt(DB.ExecuteScalar(sql.ToString(), null, Get_TrxName())) + " WHERE C_Contract_ID = " + C_Contract_ID; int res = DB.ExecuteQuery(sql1, null, Get_TrxName()); } else { sql.Append("SELECT C_Contract_ID FROM C_Contract WHERE IsActive = 'Y' AND AD_Client_ID = " + GetAD_Client_ID()); IDataReader idr = null; try { idr = DB.ExecuteReader(sql.ToString(), null, Get_TrxName()); while (idr.Read()) { cont = new VAdvantage.Model.X_C_Contract(GetCtx(), Util.GetValueOfInt(idr[0]), Get_TrxName()); string date = System.DateTime.Now.ToString("dd-MMM-yyyy"); int[] contSch = VAdvantage.Model.X_C_ContractSchedule.GetAllIDs("C_ContractSchedule", "C_Contract_ID = " + cont.GetC_Contract_ID() + " AND FROMDATE <= '" + date + "' AND NVL(C_INVOICE_ID,0) = 0", Get_TrxName()); if (contSch != null) { for (int i = 0; i < contSch.Length; i++) { contSchedule = new VAdvantage.Model.X_C_ContractSchedule(GetCtx(), Util.GetValueOfInt(contSch[i]), Get_TrxName()); GenerateInvoice(contSchedule); } } sql.Clear(); sql.Append("SELECT COUNT(C_ContractSchedule_ID) FROM C_ContractSchedule WHERE C_Contract_ID = " + cont.GetC_Contract_ID() + " AND NVL(C_INVOICE_ID,0) > 0"); string sql1 = "UPDATE C_Contract SET InvoicesGenerated = " + Util.GetValueOfInt(DB.ExecuteScalar(sql.ToString(), null, Get_TrxName())) + " WHERE C_Contract_ID = " + cont.GetC_Contract_ID(); int res = DB.ExecuteQuery(sql1, null, Get_TrxName()); } if (idr != null) { idr.Close(); idr = null; } } catch { if (idr != null) { idr.Close(); idr = null; } } } //Neha--If Invoice generated sucessfully then it will return sb.Length greater then 0 if (sb.Length > 0) { return(Msg.GetMsg(GetCtx(), "VIS_InvGenerated") + sb.ToString().Substring(0, sb.Length - 2)); } else { return(Msg.GetMsg(GetCtx(), "VIS_InvNotGenerated")); } }