/// <summary> /// GetOrder /// </summary> /// <param name="ctx"></param> /// <param name="fields"></param> /// <returns></returns> public Dictionary <String, String> GetOrder(Ctx ctx, string fields) { string[] paramValue = fields.ToString().Split(','); int C_Order_ID; //Assign parameter value C_Order_ID = Util.GetValueOfInt(paramValue[0].ToString()); MOrder order = new MOrder(ctx, C_Order_ID, null); // End Assign parameter value Dictionary <String, String> retDic = new Dictionary <string, string>(); // Reset Orig Shipment retDic["C_BPartner_ID"] = Util.GetValueOfString(order.GetC_BPartner_ID()); retDic["C_BPartner_Location_ID"] = Util.GetValueOfString(order.GetC_BPartner_Location_ID()); retDic["Bill_BPartner_ID"] = Util.GetValueOfString(order.GetBill_BPartner_ID()); retDic["Bill_Location_ID"] = Util.GetValueOfString(order.GetBill_Location_ID()); if (order.GetAD_User_ID() != 0) { retDic["AD_User_ID"] = Util.GetValueOfString(order.GetAD_User_ID()); } if (order.GetBill_User_ID() != 0) { retDic["Bill_User_ID"] = Util.GetValueOfString(order.GetBill_User_ID()); } retDic["M_PriceList_ID"] = Util.GetValueOfString(order.GetM_PriceList_ID()); retDic["PaymentRule"] = order.GetPaymentRule(); retDic["C_PaymentTerm_ID"] = Util.GetValueOfString(order.GetC_PaymentTerm_ID()); //mTab.setValue ("DeliveryRule", X_C_Order.DELIVERYRULE_Manual); retDic["Bill_Location_ID"] = Util.GetValueOfString(order.GetBill_Location_ID()); retDic["InvoiceRule"] = order.GetInvoiceRule(); retDic["PaymentRule"] = order.GetPaymentRule(); retDic["DeliveryViaRule"] = order.GetDeliveryViaRule(); retDic["FreightCostRule"] = order.GetFreightCostRule(); retDic["ID"] = Util.GetValueOfString(order.Get_ID()); retDic["DateOrdered"] = Util.GetValueOfString(order.GetDateOrdered()); retDic["POReference"] = order.GetPOReference(); retDic["AD_Org_ID"] = Util.GetValueOfString(order.GetAD_Org_ID()); retDic["DeliveryRule"] = order.GetDeliveryRule(); retDic["DeliveryViaRule"] = order.GetDeliveryViaRule(); retDic["M_Shipper_ID"] = Util.GetValueOfString(order.GetM_Shipper_ID()); retDic["FreightAmt"] = Util.GetValueOfString(order.GetFreightAmt()); retDic["AD_OrgTrx_ID"] = Util.GetValueOfString(order.GetAD_OrgTrx_ID()); retDic["C_Activity_ID"] = Util.GetValueOfString(order.GetC_Activity_ID()); retDic["C_Campaign_ID"] = Util.GetValueOfString(order.GetC_Campaign_ID()); retDic["C_Project_ID"] = Util.GetValueOfString(order.GetC_Project_ID()); retDic["User1_ID"] = Util.GetValueOfString(order.GetUser1_ID()); retDic["User2_ID"] = Util.GetValueOfString(order.GetUser2_ID()); retDic["M_Warehouse_ID"] = Util.GetValueOfString(order.GetM_Warehouse_ID()); retDic["Orig_Order_ID"] = Util.GetValueOfString(order.GetOrig_Order_ID()); retDic["Orig_InOut_ID"] = Util.GetValueOfString(order.GetOrig_InOut_ID()); return(retDic); }
/// <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); }
/// <summary> /// GetOrder /// </summary> /// <param name="ctx"></param> /// <param name="fields"></param> /// <returns></returns> public Dictionary <String, object> GetOrder(Ctx ctx, string fields) { string[] paramValue = fields.ToString().Split(','); int C_Order_ID; //Assign parameter value C_Order_ID = Util.GetValueOfInt(paramValue[0].ToString()); MOrder order = new MOrder(ctx, C_Order_ID, null); // End Assign parameter value Dictionary <String, object> retDic = new Dictionary <string, object>(); // Reset Orig Shipment retDic["C_BPartner_ID"] = Util.GetValueOfString(order.GetC_BPartner_ID()); retDic["C_BPartner_Location_ID"] = Util.GetValueOfString(order.GetC_BPartner_Location_ID()); retDic["Bill_BPartner_ID"] = Util.GetValueOfString(order.GetBill_BPartner_ID()); retDic["Bill_Location_ID"] = Util.GetValueOfString(order.GetBill_Location_ID()); if (order.GetAD_User_ID() != 0) { retDic["AD_User_ID"] = Util.GetValueOfString(order.GetAD_User_ID()); } if (order.GetBill_User_ID() != 0) { retDic["Bill_User_ID"] = Util.GetValueOfString(order.GetBill_User_ID()); } retDic["M_PriceList_ID"] = Util.GetValueOfString(order.GetM_PriceList_ID()); retDic["PaymentRule"] = order.GetPaymentRule(); retDic["C_PaymentTerm_ID"] = Util.GetValueOfString(order.GetC_PaymentTerm_ID()); //mTab.setValue ("DeliveryRule", X_C_Order.DELIVERYRULE_Manual); retDic["Bill_Location_ID"] = Util.GetValueOfString(order.GetBill_Location_ID()); retDic["InvoiceRule"] = order.GetInvoiceRule(); retDic["PaymentRule"] = order.GetPaymentRule(); retDic["DeliveryViaRule"] = order.GetDeliveryViaRule(); retDic["FreightCostRule"] = order.GetFreightCostRule(); retDic["ID"] = Util.GetValueOfString(order.Get_ID()); //retDic["DateOrdered"] = Convert.ToDateTime(order.GetDateOrdered()).ToLocalTime().ToUniversalTime(); retDic["DateOrdered"] = DateTime.SpecifyKind(order.GetDateOrdered().Value, DateTimeKind.Utc); retDic["DateAcct"] = Util.GetValueOfString(order.GetDateAcct()); retDic["POReference"] = order.GetPOReference(); retDic["AD_Org_ID"] = Util.GetValueOfString(order.GetAD_Org_ID()); retDic["DeliveryRule"] = order.GetDeliveryRule(); retDic["DeliveryViaRule"] = order.GetDeliveryViaRule(); retDic["M_Shipper_ID"] = Util.GetValueOfString(order.GetM_Shipper_ID()); retDic["FreightAmt"] = Util.GetValueOfString(order.GetFreightAmt()); retDic["AD_OrgTrx_ID"] = Util.GetValueOfString(order.GetAD_OrgTrx_ID()); retDic["C_Activity_ID"] = Util.GetValueOfString(order.GetC_Activity_ID()); retDic["C_Campaign_ID"] = Util.GetValueOfString(order.GetC_Campaign_ID()); retDic["C_Project_ID"] = Util.GetValueOfString(order.GetC_Project_ID()); retDic["User1_ID"] = Util.GetValueOfString(order.GetUser1_ID()); retDic["User2_ID"] = Util.GetValueOfString(order.GetUser2_ID()); retDic["M_Warehouse_ID"] = Util.GetValueOfString(order.GetM_Warehouse_ID()); retDic["Orig_Order_ID"] = Util.GetValueOfString(order.GetOrig_Order_ID()); retDic["Orig_InOut_ID"] = Util.GetValueOfString(order.GetOrig_InOut_ID()); //Added By Amit retDic["IsSOTrx"] = Util.GetValueOfString(order.IsSOTrx()); retDic["IsReturnTrx"] = Util.GetValueOfString(order.IsReturnTrx()); retDic["C_Payment_ID"] = Util.GetValueOfString(order.GetPaymentMethod()); retDic["VA009_PaymentMethod_ID"] = Util.GetValueOfString(order.GetVA009_PaymentMethod_ID()); retDic["SalesRep_ID"] = Util.GetValueOfString(order.GetSalesRep_ID()); retDic["C_ProjectRef_ID"] = Util.GetValueOfString(order.GetC_ProjectRef_ID()); retDic["PriorityRule"] = Util.GetValueOfString(order.GetPriorityRule()); if (order.GetC_Currency_ID() != 0) { retDic["C_Currency_ID"] = Util.GetValueOfString(order.GetC_Currency_ID()); } else { retDic["C_Currency_ID"] = "0"; } //End // added by vivek on 09/10/2017 advised by pradeep to set drop ship checkbox value retDic["IsDropShip"] = Util.GetValueOfBool(order.IsDropShip()) ? "Y" : "N"; // Added by Bharat on 30 Jan 2018 to set Inco Term from Order if (order.Get_ColumnIndex("C_IncoTerm_ID") > 0) { retDic["C_IncoTerm_ID"] = Util.GetValueOfString(order.GetC_IncoTerm_ID()); } if (Env.IsModuleInstalled("VA077_")) { retDic["VA077_HistoricContractDate"] = Util.GetValueOfString(order.Get_Value("VA077_HistoricContractDate")); retDic["VA077_ChangeStartDate"] = Util.GetValueOfString(order.Get_Value("VA077_ChangeStartDate")); retDic["VA077_ContractCPStartDate"] = Util.GetValueOfString(order.Get_Value("VA077_ContractCPStartDate")); retDic["VA077_ContractCPEndDate"] = Util.GetValueOfString(order.Get_Value("VA077_ContractCPEndDate")); retDic["VA077_PartialAmtCatchUp"] = Util.GetValueOfString(order.Get_Value("VA077_PartialAmtCatchUp")); retDic["VA077_OldAnnualContractTotal"] = Util.GetValueOfString(order.Get_Value("VA077_OldAnnualContractTotal")); retDic["VA077_AdditionalAnnualCharge"] = Util.GetValueOfString(order.Get_Value("VA077_AdditionalAnnualCharge")); retDic["VA077_NewAnnualContractTotal"] = Util.GetValueOfString(order.Get_Value("VA077_NewAnnualContractTotal")); retDic["VA077_SalesCoWorker"] = Util.GetValueOfString(order.Get_Value("VA077_SalesCoWorker")); retDic["VA077_SalesCoWorkerPer"] = Util.GetValueOfString(order.Get_Value("VA077_SalesCoWorkerPer")); retDic["VA077_TotalMarginAmt"] = Util.GetValueOfString(order.Get_Value("VA077_TotalMarginAmt")); retDic["VA077_TotalPurchaseAmt"] = Util.GetValueOfString(order.Get_Value("VA077_TotalPurchaseAmt")); retDic["VA077_TotalSalesAmt"] = Util.GetValueOfString(order.Get_Value("VA077_TotalSalesAmt")); retDic["VA077_MarginPercent"] = Util.GetValueOfString(order.Get_Value("VA077_MarginPercent")); } return(retDic); }
public JsonResult GetOrder(string param) { string retError = ""; string retJSON = ""; if (Session["ctx"] != null) { VAdvantage.Utility.Ctx ctx = Session["ctx"] as Ctx; string[] paramValue = param.Split(','); int C_Order_ID; //Assign parameter value C_Order_ID = Util.GetValueOfInt(paramValue[0].ToString()); MOrder order = new MOrder(ctx, C_Order_ID, null); Dictionary <String, String> retDic = new Dictionary <string, string>(); // Reset Orig Shipment retDic["C_BParter_ID"] = order.GetC_BPartner_ID().ToString(); retDic["C_BPartner_Location_ID"] = order.GetC_BPartner_Location_ID().ToString(); retDic["Bill_BPartner_ID"] = order.GetBill_BPartner_ID().ToString(); retDic["Bill_Location_ID"] = order.GetBill_Location_ID().ToString(); if (order.GetAD_User_ID() != 0) { retDic["AD_User_ID"] = order.GetAD_User_ID().ToString(); } if (order.GetBill_User_ID() != 0) { retDic["Bill_User_ID"] = order.GetBill_User_ID().ToString(); } //if (ctx.IsSOTrx(WindowNo)) // retDic["M_ReturnPolicy_ID"]= bpartner.getM_ReturnPolicy_ID(); //else // retDic["M_ReturnPolicy_ID"]= bpartner.getPO_ReturnPolicy_ID(); //retDic["DateOrdered", order.GetDateOrdered()); retDic["M_PriceList_ID"] = order.GetM_PriceList_ID().ToString(); retDic["PaymentRule"] = order.GetPaymentRule(); retDic["C_PaymentTerm_ID"] = order.GetC_PaymentTerm_ID().ToString(); //mTab.setValue ("DeliveryRule", X_C_Order.DELIVERYRULE_Manual); retDic["Bill_Location_ID"] = order.GetBill_Location_ID().ToString(); retDic["InvoiceRule"] = order.GetInvoiceRule(); retDic["PaymentRule"] = order.GetPaymentRule(); retDic["DeliveryViaRule"] = order.GetDeliveryViaRule(); retDic["FreightCostRule"] = order.GetFreightCostRule(); //retlst.Add(retValue); //retVal.Add(notReserved); retJSON = JsonConvert.SerializeObject(retDic); } else { retError = "Session Expired"; } return(Json(new { result = retJSON, error = retError }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Generate Invoices /// </summary> /// <param name="idr">pstmt order query</param> /// <returns>info</returns> //private String Generate(IDataReader idr) private String Generate(DataTable dt) { //JID_1139 Avoided the duplicate charge line created Invoice(customer) bool isAllownonItem = Util.GetValueOfString(GetCtx().GetContext("$AllowNonItem")).Equals("Y"); foreach (DataRow dr in dt.Rows) { MOrder order = new MOrder(GetCtx(), dr, Get_TrxName()); // Credit Limit check MBPartner bp = MBPartner.Get(GetCtx(), order.GetC_BPartner_ID()); if (bp.GetCreditStatusSettingOn() == "CH") { decimal creditLimit = bp.GetSO_CreditLimit(); string creditVal = bp.GetCreditValidation(); if (creditLimit != 0) { decimal creditAvlb = creditLimit - bp.GetSO_CreditUsed(); if (creditAvlb <= 0) { if (creditVal == "C" || creditVal == "D" || creditVal == "F") { AddLog(Msg.GetMsg(GetCtx(), "StopInvoice") + bp.GetName()); continue; } else if (creditVal == "I" || creditVal == "J" || creditVal == "L") { if (_msg != null) { _msg.Clear(); } _msg.Append(Msg.GetMsg(GetCtx(), "WarningInvoice") + bp.GetName()); //AddLog(Msg.GetMsg(GetCtx(), "WarningInvoice") + bp.GetName()); } } } } // JID_0161 // change here now will check credit settings on field only on Business Partner Header // Lokesh Chauhan 15 July 2019 else if (bp.GetCreditStatusSettingOn() == X_C_BPartner.CREDITSTATUSSETTINGON_CustomerLocation) { MBPartnerLocation bpl = new MBPartnerLocation(GetCtx(), order.GetC_BPartner_Location_ID(), null); //MBPartner bpartner = MBPartner.Get(GetCtx(), order.GetC_BPartner_ID()); //if (bpl.GetCreditStatusSettingOn() == "CL") //{ decimal creditLimit = bpl.GetSO_CreditLimit(); string creditVal = bpl.GetCreditValidation(); if (creditLimit != 0) { decimal creditAvlb = creditLimit - bpl.GetSO_CreditUsed(); if (creditAvlb <= 0) { if (creditVal == "C" || creditVal == "D" || creditVal == "F") { AddLog(Msg.GetMsg(GetCtx(), "StopInvoice") + bp.GetName() + " " + bpl.GetName()); continue; } else if (creditVal == "I" || creditVal == "J" || creditVal == "L") { if (_msg != null) { _msg.Clear(); } _msg.Append(Msg.GetMsg(GetCtx(), "WarningInvoice") + bp.GetName() + " " + bpl.GetName()); //AddLog(Msg.GetMsg(GetCtx(), "WarningInvoice") + bp.GetName() + " " + bpl.GetName()); } } } //} } // Credit Limit End // New Invoice Location // JID_1237 : While creating invoice need to consolidate order on the basis of Org, Payment Term, BP Location (Bill to Location) and Pricelist. if (!_ConsolidateDocument || (_invoice != null && (_invoice.GetC_BPartner_Location_ID() != order.GetBill_Location_ID() || _invoice.GetC_PaymentTerm_ID() != order.GetC_PaymentTerm_ID() || _invoice.GetM_PriceList_ID() != order.GetM_PriceList_ID() || _invoice.GetAD_Org_ID() != order.GetAD_Org_ID() || ((_invoice.GetC_ConversionType_ID() != 0 ? _invoice.GetC_ConversionType_ID() : defaultConversionType) != (order.GetC_ConversionType_ID() != 0 ? order.GetC_ConversionType_ID() : defaultConversionType)) ))) { CompleteInvoice(); } bool completeOrder = MOrder.INVOICERULE_AfterOrderDelivered.Equals(order.GetInvoiceRule()); // Schedule After Delivery bool doInvoice = false; if (MOrder.INVOICERULE_CustomerScheduleAfterDelivery.Equals(order.GetInvoiceRule())) { _bp = new MBPartner(GetCtx(), order.GetBill_BPartner_ID(), null); if (_bp.GetC_InvoiceSchedule_ID() == 0) { log.Warning("BPartner has no Schedule - set to After Delivery"); order.SetInvoiceRule(MOrder.INVOICERULE_AfterDelivery); order.Save(); } else { MInvoiceSchedule ins = MInvoiceSchedule.Get(GetCtx(), _bp.GetC_InvoiceSchedule_ID(), Get_TrxName()); if (ins.CanInvoice(order.GetDateOrdered(), order.GetGrandTotal())) { doInvoice = true; } else { continue; } } } // Schedule // After Delivery if (doInvoice || MOrder.INVOICERULE_AfterDelivery.Equals(order.GetInvoiceRule())) { MInOut shipment = null; MInOutLine[] shipmentLines = order.GetShipmentLines(); MOrderLine[] oLines = order.GetLines(true, null); for (int i = 0; i < shipmentLines.Length; i++) { MInOutLine shipLine = shipmentLines[i]; if (shipLine.IsInvoiced()) { continue; } if (shipment == null || shipment.GetM_InOut_ID() != shipLine.GetM_InOut_ID()) { shipment = new MInOut(GetCtx(), shipLine.GetM_InOut_ID(), Get_TrxName()); } if (!shipment.IsComplete() || // ignore incomplete or reversals shipment.GetDocStatus().Equals(MInOut.DOCSTATUS_Reversed)) { continue; } //JID_1139 Avoided the duplicate charge records if (shipLine.GetM_Product_ID() > 0 || isAllownonItem) { CreateLine(order, shipment, shipLine); } }// shipment lines //JID_1139 Avoided the duplicate charge records if (!isAllownonItem) { for (int i = 0; i < oLines.Length; i++) { MOrderLine oLine = oLines[i]; if (oLine.GetC_Charge_ID() > 0) { Decimal toInvoice = Decimal.Subtract(oLine.GetQtyOrdered(), oLine.GetQtyInvoiced()); log.Fine("Immediate - ToInvoice=" + toInvoice + " - " + oLine); Decimal qtyEntered = toInvoice; // Correct UOM for QtyEntered if (oLine.GetQtyEntered().CompareTo(oLine.GetQtyOrdered()) != 0) { qtyEntered = Decimal.Round(Decimal.Divide(Decimal.Multiply( toInvoice, oLine.GetQtyEntered()), oLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero); } //JID_1139_1 avoided the charge line with 0 qty inserted if (oLine.IsContract() == false && oLine.GetQtyOrdered() > oLine.GetQtyInvoiced()) { CreateLine(order, oLine, toInvoice, qtyEntered); log.Info("ID " + oLine.Get_ID() + "Qty Ordered " + oLine.GetQtyOrdered() + " Qty Invoiced " + oLine.GetQtyInvoiced()); } } } } } // After Order Delivered, Immediate else { MOrderLine[] oLines = order.GetLines(true, null); for (int i = 0; i < oLines.Length; i++) { MOrderLine oLine = oLines[i]; Decimal toInvoice = Decimal.Subtract(oLine.GetQtyOrdered(), oLine.GetQtyInvoiced()); if (toInvoice.CompareTo(Env.ZERO) == 0 && oLine.GetM_Product_ID() != 0) { continue; } // bool fullyDelivered = oLine.GetQtyOrdered().CompareTo(oLine.GetQtyDelivered()) == 0; //JID_1136: While creating the Invoices against the charge system should not check the Ordered qty= Delivered qty. need to check this only in case of products if (completeOrder && oLine.GetC_Charge_ID() > 0) { fullyDelivered = true; if (oLine.GetC_Charge_ID() > 0) { log.Fine("After Order Delivery - ToInvoice=" + toInvoice + " - " + oLine); Decimal qtyEntered = toInvoice; // Correct UOM for QtyEntered if (oLine.GetQtyEntered().CompareTo(oLine.GetQtyOrdered()) != 0) { qtyEntered = Decimal.Round(Decimal.Divide(Decimal.Multiply( toInvoice, oLine.GetQtyEntered()), oLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero); } // if (oLine.IsContract() == false && !isAllownonItem) { CreateLine(order, oLine, toInvoice, qtyEntered); log.Info("ID " + oLine.Get_ID() + "Qty Ordered " + oLine.GetQtyOrdered() + " Qty Invoiced " + oLine.GetQtyInvoiced()); } } } // Complete Order if (completeOrder && !fullyDelivered) { log.Fine("Failed CompleteOrder - " + oLine); completeOrder = false; break; } // Immediate else if (MOrder.INVOICERULE_Immediate.Equals(order.GetInvoiceRule())) { log.Fine("Immediate - ToInvoice=" + toInvoice + " - " + oLine); Decimal qtyEntered = toInvoice; // Correct UOM for QtyEntered if (oLine.GetQtyEntered().CompareTo(oLine.GetQtyOrdered()) != 0) { qtyEntered = Decimal.Round(Decimal.Divide(Decimal.Multiply( toInvoice, oLine.GetQtyEntered()), oLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero); } // if (oLine.IsContract() == false) { CreateLine(order, oLine, toInvoice, qtyEntered); log.Info("ID " + oLine.Get_ID() + "Qty Ordered " + oLine.GetQtyOrdered() + " Qty Invoiced " + oLine.GetQtyInvoiced()); } } else { log.Fine("Failed: " + order.GetInvoiceRule() + " - ToInvoice=" + toInvoice + " - " + oLine); } } // for all order lines if (MOrder.INVOICERULE_Immediate.Equals(order.GetInvoiceRule())) { _line += 1000; } } // Complete Order successful if (completeOrder && MOrder.INVOICERULE_AfterOrderDelivered.Equals(order.GetInvoiceRule())) { MInOut[] shipments = order.GetShipments(true); for (int i = 0; i < shipments.Length; i++) { MInOut ship = shipments[i]; if (!ship.IsComplete() || // ignore incomplete or reversals ship.GetDocStatus().Equals(MInOut.DOCSTATUS_Reversed)) { continue; } MInOutLine[] shipLines = ship.GetLines(false); for (int j = 0; j < shipLines.Length; j++) { MInOutLine shipLine = shipLines[j]; if (!order.IsOrderLine(shipLine.GetC_OrderLine_ID())) { continue; } if (!shipLine.IsInvoiced()) { CreateLine(order, ship, shipLine); } } // lines _line += 1000; } // all shipments } // complete Order } // for all orders CompleteInvoice(); return("@Created@ = " + _created); }
/// <summary> /// Create actual Payment /// </summary> /// <param name="C_Invoice_ID">invoice</param> /// <param name="C_BPartner_ID">partner ignored when invoice exists</param> /// <param name="C_Currency_ID">currency</param> /// <param name="stmtAmt">statement amount</param> /// <param name="trxAmt">transaction amt</param> /// <param name="C_BankAccount_ID">bank account</param> /// <param name="dateTrx">transaction date</param> /// <param name="dateAcct">accounting date</param> /// <param name="description">description</param> /// <param name="AD_Org_ID"></param> /// <param name="C_ConversionType_ID">C_ConversionType_ID</param> /// <param name="C_Order_ID">C_Order_ID</param> /// <returns>payment</returns> private MPayment CreatePayment(int C_Invoice_ID, int C_BPartner_ID, int C_Currency_ID, Decimal stmtAmt, Decimal trxAmt, int C_BankAccount_ID, DateTime?dateTrx, DateTime?dateAcct, String description, int AD_Org_ID, int C_ConversionType_ID, int C_Order_ID) { // Trx Amount = Payment overwrites Statement Amount if defined Decimal payAmt = trxAmt; if (Env.ZERO.CompareTo(payAmt) == 0) { payAmt = stmtAmt; } if (C_Invoice_ID == 0 && C_Order_ID == 0 && (Env.ZERO.CompareTo(payAmt) == 0)) { throw new Exception("@PayAmt@ = 0"); } //if (payAmt == null) //{ // payAmt = Env.ZERO; //} // MPayment payment = new MPayment(GetCtx(), 0, Get_Trx()); payment.SetAD_Org_ID(AD_Org_ID); payment.SetC_BankAccount_ID(C_BankAccount_ID); //payment.SetTenderType(MPayment.TENDERTYPE_Check);//not required it will update on MPayment class //Get the C_ConversionType_ID from BankStatementLine and Set C_ConversionType_ID for Payment payment.SetC_ConversionType_ID(C_ConversionType_ID); if (dateTrx != null) { payment.SetDateTrx(dateTrx); } else if (dateAcct != null) { payment.SetDateTrx(dateAcct); } if (dateAcct != null) { payment.SetDateAcct(dateAcct); } else { payment.SetDateAcct(payment.GetDateTrx()); } payment.SetDescription(description); // if (C_Invoice_ID != 0) { MInvoice invoice = new MInvoice(GetCtx(), C_Invoice_ID, Get_Trx()); //Used Trx payment.SetC_DocType_ID(invoice.IsSOTrx()); // Receipt payment.SetC_BPartner_ID(invoice.GetC_BPartner_ID()); //set the BPartner Location from the Invoice payment.SetC_BPartner_Location_ID(invoice.GetC_BPartner_Location_ID()); //set the PaymentMethod by the reference of Invoice payment.SetVA009_PaymentMethod_ID(invoice.GetVA009_PaymentMethod_ID()); payment.SetC_Currency_ID(invoice.GetC_Currency_ID()); decimal _dueAmt = 0; string _sql = "SELECT * FROM C_InvoicePaySchedule WHERE VA009_PAIDAMNT IS NULL AND VA009_IsPaid = 'N' AND IsActive = 'Y' AND C_Invoice_ID =" + invoice.GetC_Invoice_ID(); DataSet _ds = DB.ExecuteDataset(_sql, null, Get_Trx()); if (_ds != null && _ds.Tables[0].Rows.Count == 1) { payment.SetC_Invoice_ID(invoice.GetC_Invoice_ID());//set Invoice Reference payment.SetC_InvoicePaySchedule_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[0]["C_INVOICEPAYSCHEDULE_ID"])); _dueAmt = Util.GetValueOfDecimal(_ds.Tables[0].Rows[0]["DUEAMT"]); //Set PayAmt -ve sign Incase of DocBaseType APC or ARC - IsReturnTrx is true //Set PayAmt +ve sign Incase of DocBaseType API or ARI - IsReturnTrx is false if (!invoice.IsReturnTrx()) { payment.SetPayAmt(_dueAmt); } else // payment is likely to be negative { payment.SetPayAmt(Decimal.Negate(_dueAmt)); } if (!payment.Save(Get_Trx())) { Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); //to get Exact Error Message first get Value from GetName() else GetValue() string error = pp != null?pp.GetName() : ""; if (string.IsNullOrEmpty(error)) { error = pp != null?pp.GetValue() : ""; if (string.IsNullOrEmpty(error)) { error = pp != null?pp.ToString() : ""; } } _message = !string.IsNullOrEmpty(error) ? error : "VA012_PaymentNotSaved"; return(null); } } else if (_ds != null && _ds.Tables[0].Rows.Count > 1) { if (!payment.Save(Get_Trx())) { Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); //to get Exact Error Message first get Value from GetName() else GetValue() string error = pp != null?pp.GetName() : ""; if (string.IsNullOrEmpty(error)) { error = pp != null?pp.GetValue() : ""; if (string.IsNullOrEmpty(error)) { error = pp != null?pp.ToString() : ""; } } _message = !string.IsNullOrEmpty(error) ? error : "VA012_PaymentNotSaved"; return(null); } else { //Initialize the Object for MPaymentAllocate class MPaymentAllocate PayAlocate = null; for (int i = 0; _ds.Tables[0].Rows.Count > i; i++) { //Create the Object for MPaymentAllocate class for every Iteration PayAlocate = new MPaymentAllocate(GetCtx(), 0, Get_Trx()); PayAlocate.SetC_Payment_ID(payment.GetC_Payment_ID()); PayAlocate.SetAD_Client_ID(payment.GetAD_Client_ID()); //set Organization with the reference of Bank Account PayAlocate.SetAD_Org_ID(payment.GetAD_Org_ID());//set Org_ID from the Header PayAlocate.SetC_Invoice_ID(invoice.GetC_Invoice_ID()); PayAlocate.SetC_InvoicePaySchedule_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["C_INVOICEPAYSCHEDULE_ID"])); //Set PayAmt -ve sign Incase of DocBaseType APC or ARC - IsReturnTrx is true //Set PayAmt +ve sign Incase of DocBaseType API or ARI - IsReturnTrx is false if (!invoice.IsReturnTrx()) { PayAlocate.SetInvoiceAmt(Util.GetValueOfDecimal(_ds.Tables[0].Rows[i]["DUEAMT"])); PayAlocate.SetAmount(Util.GetValueOfDecimal(_ds.Tables[0].Rows[i]["DUEAMT"])); } else { PayAlocate.SetInvoiceAmt(-1 * Util.GetValueOfDecimal(_ds.Tables[0].Rows[i]["DUEAMT"])); PayAlocate.SetAmount(-1 * Util.GetValueOfDecimal(_ds.Tables[0].Rows[i]["DUEAMT"])); } if (!PayAlocate.Save(Get_Trx())) { Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); //to get Exact Error Message first get Value from GetName() else GetValue() string error = pp != null?pp.GetName() : ""; if (string.IsNullOrEmpty(error)) { error = pp != null?pp.GetValue() : ""; if (string.IsNullOrEmpty(error)) { error = pp != null?pp.ToString() : ""; } } _message = !string.IsNullOrEmpty(error) ? error : "VA012_PaymentNotSaved"; return(null); } } } } } else if (C_Order_ID > 0 && C_BPartner_ID > 0) // Create Payment for prePayOrder reference { MOrder order = new MOrder(GetCtx(), C_Order_ID, Get_Trx()); payment.SetC_Order_ID(C_Order_ID); payment.SetC_DocType_ID(order.IsSOTrx()); // Receipt payment.SetC_BPartner_ID(order.GetC_BPartner_ID()); payment.SetC_BPartner_Location_ID(order.GetC_BPartner_Location_ID()); payment.SetC_Currency_ID(order.GetC_Currency_ID()); payment.SetVA009_PaymentMethod_ID(order.GetVA009_PaymentMethod_ID()); payment.SetPayAmt(order.GetGrandTotal()); if (!payment.Save(Get_Trx())) { Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); //to get Exact Error Message first get Value from GetName() else GetValue() string error = pp != null?pp.GetName() : ""; if (string.IsNullOrEmpty(error)) { error = pp != null?pp.GetValue() : ""; if (string.IsNullOrEmpty(error)) { error = pp != null?pp.ToString() : ""; } } _message = !string.IsNullOrEmpty(error) ? error : "VA012_PaymentNotSaved"; return(null); } } else { _message = "VA012_ReferenceNotfoundtoCreatePayment"; return(null); } //Commit the Transaction Get_Trx().Commit(); //Call Complete Method to Complete the Record //149 is AD_Process_ID for C_Payment_Process _message = CompletePayment(GetCtx(), payment.GetC_Payment_ID(), 149, MPayment.DOCACTION_Complete); if (!string.IsNullOrEmpty(_message)) { return(null); } return(payment); }
} // 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
/** * Generate Shipments * @param pstmt order query * @return info */ private String Generate(IDataReader idr) { DataTable dt = new DataTable(); try { dt.Load(idr); idr.Close(); foreach (DataRow dr in dt.Rows)// while (dr.next ()) { MOrder order = new MOrder(GetCtx(), dr, Get_TrxName()); // Credit Limit check added by Vivek on 24/08/2016 MBPartner bp = MBPartner.Get(GetCtx(), order.GetC_BPartner_ID()); if (bp.GetCreditStatusSettingOn() == "CH") { decimal creditLimit = bp.GetSO_CreditLimit(); string creditVal = bp.GetCreditValidation(); if (creditLimit != 0) { decimal creditAvlb = creditLimit - bp.GetSO_CreditUsed(); if (creditAvlb <= 0) { if (creditVal == "C" || creditVal == "D" || creditVal == "F") { AddLog(Msg.GetMsg(GetCtx(), "StopInvoice") + bp.GetName()); continue; } else if (creditVal == "I" || creditVal == "J" || creditVal == "L") { if (_msg != null) { _msg.Clear(); } _msg.Append(Msg.GetMsg(GetCtx(), "WarningInvoice") + bp.GetName()); //AddLog(Msg.GetMsg(GetCtx(), "WarningInvoice") + bp.GetName()); } } } } else { MBPartnerLocation bpl = new MBPartnerLocation(GetCtx(), order.GetC_BPartner_Location_ID(), null); MBPartner bpartner = MBPartner.Get(GetCtx(), order.GetC_BPartner_ID()); if (bpl.GetCreditStatusSettingOn() == "CL") { decimal creditLimit = bpl.GetSO_CreditLimit(); string creditVal = bpl.GetCreditValidation(); if (creditLimit != 0) { decimal creditAvlb = creditLimit - bpl.GetSO_CreditUsed(); if (creditAvlb <= 0) { if (creditVal == "C" || creditVal == "D" || creditVal == "F") { AddLog(Msg.GetMsg(GetCtx(), "StopInvoice") + bp.GetName() + " " + bpl.GetName()); continue; } else if (creditVal == "I" || creditVal == "J" || creditVal == "L") { if (_msg != null) { _msg.Clear(); } _msg.Append(Msg.GetMsg(GetCtx(), "WarningInvoice") + bp.GetName() + " " + bpl.GetName()); //AddLog(Msg.GetMsg(GetCtx(), "WarningInvoice") + bp.GetName() + " " + bpl.GetName()); } } } } } // Credit Limit End // New Invoice Location if (!_ConsolidateDocument || (_invoice != null && (_invoice.GetC_BPartner_Location_ID() != order.GetBill_Location_ID() || _invoice.GetC_PaymentTerm_ID() != order.GetC_PaymentTerm_ID()))) { CompleteInvoice(); } bool completeOrder = MOrder.INVOICERULE_AfterOrderDelivered.Equals(order.GetInvoiceRule()); // Schedule After Delivery bool doInvoice = false; if (MOrder.INVOICERULE_CustomerScheduleAfterDelivery.Equals(order.GetInvoiceRule())) { _bp = new MBPartner(GetCtx(), order.GetBill_BPartner_ID(), null); if (_bp.GetC_InvoiceSchedule_ID() == 0) { log.Warning("BPartner has no Schedule - set to After Delivery"); order.SetInvoiceRule(MOrder.INVOICERULE_AfterDelivery); order.Save(); } else { MInvoiceSchedule ins = MInvoiceSchedule.Get(GetCtx(), _bp.GetC_InvoiceSchedule_ID(), Get_TrxName()); if (ins.CanInvoice(order.GetDateOrdered(), order.GetGrandTotal())) { doInvoice = true; } else { continue; } } } // Schedule // After Delivery if (doInvoice || MOrder.INVOICERULE_AfterDelivery.Equals(order.GetInvoiceRule())) { MInOut shipment = null; MInOutLine[] shipmentLines = order.GetShipmentLines(); MOrderLine[] oLines = order.GetLines(true, null); for (int i = 0; i < shipmentLines.Length; i++) { MInOutLine shipLine = shipmentLines[i]; if (shipLine.IsInvoiced()) { continue; } if (shipment == null || shipment.GetM_InOut_ID() != shipLine.GetM_InOut_ID()) { shipment = new MInOut(GetCtx(), shipLine.GetM_InOut_ID(), Get_TrxName()); } if (!shipment.IsComplete() || // ignore incomplete or reversals shipment.GetDocStatus().Equals(MInOut.DOCSTATUS_Reversed)) { continue; } // CreateLine(order, shipment, shipLine); } // shipment lines for (int i = 0; i < oLines.Length; i++) { MOrderLine oLine = oLines[i]; if (oLine.GetC_Charge_ID() > 0) { Decimal toInvoice = Decimal.Subtract(oLine.GetQtyOrdered(), oLine.GetQtyInvoiced()); log.Fine("Immediate - ToInvoice=" + toInvoice + " - " + oLine); Decimal qtyEntered = toInvoice; // Correct UOM for QtyEntered if (oLine.GetQtyEntered().CompareTo(oLine.GetQtyOrdered()) != 0) { qtyEntered = Decimal.Round(Decimal.Divide(Decimal.Multiply( toInvoice, oLine.GetQtyEntered()), oLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero); } // if (oLine.IsContract() == false) { CreateLine(order, oLine, toInvoice, qtyEntered); log.Info("ID " + oLine.Get_ID() + "Qty Ordered " + oLine.GetQtyOrdered() + " Qty Invoiced " + oLine.GetQtyInvoiced()); } } } } // After Order Delivered, Immediate else { MOrderLine[] oLines = order.GetLines(true, null); for (int i = 0; i < oLines.Length; i++) { MOrderLine oLine = oLines[i]; Decimal toInvoice = Decimal.Subtract(oLine.GetQtyOrdered(), oLine.GetQtyInvoiced()); if (toInvoice.CompareTo(Env.ZERO) == 0 && oLine.GetM_Product_ID() != 0) { continue; } // bool fullyDelivered = oLine.GetQtyOrdered().CompareTo(oLine.GetQtyDelivered()) == 0; // Complete Order if (completeOrder && !fullyDelivered) { log.Fine("Failed CompleteOrder - " + oLine); completeOrder = false; break; } // Immediate else if (MOrder.INVOICERULE_Immediate.Equals(order.GetInvoiceRule())) { log.Fine("Immediate - ToInvoice=" + toInvoice + " - " + oLine); Decimal qtyEntered = toInvoice; // Correct UOM for QtyEntered if (oLine.GetQtyEntered().CompareTo(oLine.GetQtyOrdered()) != 0) { qtyEntered = Decimal.Round(Decimal.Divide(Decimal.Multiply( toInvoice, oLine.GetQtyEntered()), oLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero); } // if (oLine.IsContract() == false) { CreateLine(order, oLine, toInvoice, qtyEntered); log.Info("ID " + oLine.Get_ID() + "Qty Ordered " + oLine.GetQtyOrdered() + " Qty Invoiced " + oLine.GetQtyInvoiced()); } } else { log.Fine("Failed: " + order.GetInvoiceRule() + " - ToInvoice=" + toInvoice + " - " + oLine); } } // for all order lines if (MOrder.INVOICERULE_Immediate.Equals(order.GetInvoiceRule())) { _line += 1000; } } // Complete Order successful if (completeOrder && MOrder.INVOICERULE_AfterOrderDelivered.Equals(order.GetInvoiceRule())) { MInOut[] shipments = order.GetShipments(true); for (int i = 0; i < shipments.Length; i++) { MInOut ship = shipments[i]; if (!ship.IsComplete() || // ignore incomplete or reversals ship.GetDocStatus().Equals(MInOut.DOCSTATUS_Reversed)) { continue; } MInOutLine[] shipLines = ship.GetLines(false); for (int j = 0; j < shipLines.Length; j++) { MInOutLine shipLine = shipLines[j]; if (!order.IsOrderLine(shipLine.GetC_OrderLine_ID())) { continue; } if (!shipLine.IsInvoiced()) { CreateLine(order, ship, shipLine); } } // lines _line += 1000; } // all shipments } // complete Order } // for all orders } catch (Exception e) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, "", e); } finally { if (idr != null) { idr.Close(); } dt = null; } CompleteInvoice(); return("@Created@ = " + _created); }
/// <summary> /// Create 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 Line /// </summary> /// <param name="order">order</param> /// <param name="orderLine">line</param> /// <param name="qty">Quantity</param> /// <param name="storages">storage info</param> /// <param name="force">force delivery</param> private void CreateLine(MOrder order, MOrderLine orderLine, Decimal qty, MStorage[] storages, bool force) { // Complete last Shipment - can have multiple shipments if (_lastC_BPartner_Location_ID != orderLine.GetC_BPartner_Location_ID()) { CompleteShipment(); } _lastC_BPartner_Location_ID = orderLine.GetC_BPartner_Location_ID(); // Create New Shipment if (_shipment == null) { _shipment = new MInOut(order, 0, _movementDate); _shipment.SetM_Warehouse_ID(orderLine.GetM_Warehouse_ID()); // sets Org too if (order.GetC_BPartner_ID() != orderLine.GetC_BPartner_ID()) { _shipment.SetC_BPartner_ID(orderLine.GetC_BPartner_ID()); } if (order.GetC_BPartner_Location_ID() != orderLine.GetC_BPartner_Location_ID()) { _shipment.SetC_BPartner_Location_ID(orderLine.GetC_BPartner_Location_ID()); } if (!_shipment.Save()) { throw new Exception("Could not create Shipment"); } } // Non Inventory Lines if (storages == null) { MInOutLine line = new MInOutLine(_shipment); line.SetOrderLine(orderLine, 0, Env.ZERO); line.SetQty(qty); // Correct UOM if (orderLine.GetQtyEntered().CompareTo(orderLine.GetQtyOrdered()) != 0) { line.SetQtyEntered(Decimal.Round(Decimal.Divide(Decimal.Multiply(qty, orderLine.GetQtyEntered()), orderLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero)); } line.SetLine(_line + orderLine.GetLine()); //Amit 27-jan-2014 if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='DTD001_'")) > 0) { line.SetDTD001_IsAttributeNo(true); } if (!line.Save()) { throw new Exception("Could not create Shipment Line"); } log.Fine(line.ToString()); return; } // Product MProduct product = orderLine.GetProduct(); bool linePerASI = false; if (product.GetM_AttributeSet_ID() != 0) { MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); linePerASI = mas.IsInstanceAttribute(); } // Inventory Lines List <MInOutLine> list = new List <MInOutLine>(); Decimal toDeliver = qty; for (int i = 0; i < storages.Length; i++) { MStorage storage = storages[i]; Decimal deliver = toDeliver; // Not enough On Hand if (deliver.CompareTo(storage.GetQtyOnHand()) > 0 && Env.Signum(storage.GetQtyOnHand()) >= 0) // positive storage { if (!force || // Adjust to OnHand Qty (i + 1 != storages.Length)) // if force don't adjust last location { deliver = storage.GetQtyOnHand(); } } if (Env.Signum(deliver) == 0) // zero deliver { continue; } int M_Locator_ID = storage.GetM_Locator_ID(); // MInOutLine line = null; if (!linePerASI) // find line with Locator { for (int n = 0; n < list.Count; n++) { MInOutLine test = (MInOutLine)list[n]; if (test.GetM_Locator_ID() == M_Locator_ID) { line = test; break; } } } if (line == null) // new line { line = new MInOutLine(_shipment); line.SetOrderLine(orderLine, M_Locator_ID, order.IsSOTrx() ? deliver : Env.ZERO); line.SetQty(deliver); list.Add(line); } else { // existing line line.SetQty(Decimal.Add(line.GetMovementQty(), deliver)); } if (orderLine.GetQtyEntered().CompareTo(orderLine.GetQtyOrdered()) != 0) { line.SetQtyEntered(Decimal.Round(Decimal.Divide(Decimal.Multiply(line.GetMovementQty(), orderLine.GetQtyEntered()), orderLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero)); } line.SetLine(_line + orderLine.GetLine()); if (linePerASI) { line.SetM_AttributeSetInstance_ID(storage.GetM_AttributeSetInstance_ID()); } //Amit 27-jan-2014 if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='DTD001_'")) > 0) { line.SetDTD001_IsAttributeNo(true); } if (!line.Save()) { throw new Exception("Could not create Shipment Line"); } log.Fine("ToDeliver=" + qty + "/" + deliver + " - " + line); toDeliver = Decimal.Subtract(toDeliver, deliver); // Temp adjustment storage.SetQtyOnHand(Decimal.Subtract(storage.GetQtyOnHand(), deliver)); // if (Env.Signum(toDeliver) == 0) { break; } } if (Env.Signum(toDeliver) != 0) { throw new Exception("Not All Delivered - Remainder=" + toDeliver); } }
/// <summary> /// Generate Shipments /// </summary> /// <param name="idr">Order Query</param> /// <returns>info</returns> private String Generate(IDataReader idr) { DataTable dt = new DataTable(); MClient client = MClient.Get(GetCtx()); try { dt.Load(idr); idr.Close(); //ResultSet dr = pstmt.executeQuery(); foreach (DataRow dr in dt.Rows)// while (dr.next ()) // Order { MOrder order = new MOrder(GetCtx(), dr, Get_TrxName()); // New Header different Shipper, Shipment Location if (!_consolidateDocument || (_shipment != null && (_shipment.GetC_BPartner_Location_ID() != order.GetC_BPartner_Location_ID() || _shipment.GetM_Shipper_ID() != order.GetM_Shipper_ID()))) { CompleteShipment(); } log.Fine("check: " + order + " - DeliveryRule=" + order.GetDeliveryRule()); // DateTime?minGuaranteeDate = _movementDate; bool completeOrder = MOrder.DELIVERYRULE_CompleteOrder.Equals(order.GetDeliveryRule()); // OrderLine WHERE String where = " AND M_Warehouse_ID=" + _M_Warehouse_ID; if (_datePromised != null) { where += " AND (TRUNC(DatePromised,'DD')<=" + DB.TO_DATE((DateTime?)_datePromised, true) + " OR DatePromised IS NULL)"; //where += " AND (TRUNC(DatePromised,'DD')<='" + String.Format("{0:dd-MMM-yy}", _datePromised) // + "' OR DatePromised IS NULL)"; } // Exclude Auto Delivery if not Force if (!MOrder.DELIVERYRULE_Force.Equals(order.GetDeliveryRule())) { where += " AND (C_OrderLine.M_Product_ID IS NULL" + " OR EXISTS (SELECT * FROM M_Product p " + "WHERE C_OrderLine.M_Product_ID=p.M_Product_ID" + " AND IsExcludeAutoDelivery='N'))"; } // Exclude Unconfirmed if (!_isUnconfirmedInOut) { where += " AND NOT EXISTS (SELECT * FROM M_InOutLine iol" + " INNER JOIN M_InOut io ON (iol.M_InOut_ID=io.M_InOut_ID) " + "WHERE iol.C_OrderLine_ID=C_OrderLine.C_OrderLine_ID AND io.DocStatus IN ('IP','WC'))"; } // Deadlock Prevention - Order by M_Product_ID MOrderLine[] lines = order.GetLines(where, "ORDER BY C_BPartner_Location_ID, M_Product_ID"); for (int i = 0; i < lines.Length; i++) { MOrderLine line = lines[i]; if (line.GetM_Warehouse_ID() != _M_Warehouse_ID) { continue; } log.Fine("check: " + line); Decimal onHand = Env.ZERO; Decimal toDeliver = Decimal.Subtract(line.GetQtyOrdered(), line.GetQtyDelivered()); MProduct product = line.GetProduct(); // Nothing to Deliver if (product != null && Env.Signum(toDeliver) == 0) { continue; } // Check / adjust for confirmations Decimal unconfirmedShippedQty = Env.ZERO; if (_isUnconfirmedInOut && product != null && Env.Signum(toDeliver) != 0) { String where2 = "EXISTS (SELECT * FROM M_InOut io WHERE io.M_InOut_ID=M_InOutLine.M_InOut_ID AND io.DocStatus IN ('IP','WC'))"; MInOutLine[] iols = MInOutLine.GetOfOrderLine(GetCtx(), line.GetC_OrderLine_ID(), where2, null); for (int j = 0; j < iols.Length; j++) { unconfirmedShippedQty = Decimal.Add(unconfirmedShippedQty, iols[j].GetMovementQty()); } String logInfo = "Unconfirmed Qty=" + unconfirmedShippedQty + " - ToDeliver=" + toDeliver + "->"; toDeliver = Decimal.Subtract(toDeliver, unconfirmedShippedQty); logInfo += toDeliver; if (Env.Signum(toDeliver) < 0) { toDeliver = Env.ZERO; logInfo += " (set to 0)"; } // Adjust On Hand onHand = Decimal.Subtract(onHand, unconfirmedShippedQty); log.Fine(logInfo); } // Comments & lines w/o product & services if ((product == null || !product.IsStocked()) && (Env.Signum(line.GetQtyOrdered()) == 0 || // comments Env.Signum(toDeliver) != 0)) // lines w/o product { if (!MOrder.DELIVERYRULE_CompleteOrder.Equals(order.GetDeliveryRule())) // printed later { CreateLine(order, line, toDeliver, null, false); } continue; } // Stored Product MProductCategory pc = MProductCategory.Get(order.GetCtx(), product.GetM_Product_Category_ID()); String MMPolicy = pc.GetMMPolicy(); if (MMPolicy == null || MMPolicy.Length == 0) { MMPolicy = client.GetMMPolicy(); } // MStorage[] storages = GetStorages(line.GetM_Warehouse_ID(), line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), product.GetM_AttributeSet_ID(), line.GetM_AttributeSetInstance_ID() == 0, (DateTime?)minGuaranteeDate, MClient.MMPOLICY_FiFo.Equals(MMPolicy)); for (int j = 0; j < storages.Length; j++) { MStorage storage = storages[j]; onHand = Decimal.Add(onHand, storage.GetQtyOnHand()); } bool fullLine = onHand.CompareTo(toDeliver) >= 0 || Env.Signum(toDeliver) < 0; // Complete Order if (completeOrder && !fullLine) { log.Fine("Failed CompleteOrder - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + " - " + line); completeOrder = false; break; } // Complete Line else if (fullLine && MOrder.DELIVERYRULE_CompleteLine.Equals(order.GetDeliveryRule())) { log.Fine("CompleteLine - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ", ToDeliver=" + toDeliver + " - " + line); // CreateLine(order, line, toDeliver, storages, false); } // Availability else if (MOrder.DELIVERYRULE_Availability.Equals(order.GetDeliveryRule()) && (Env.Signum(onHand) > 0 || Env.Signum(toDeliver) < 0)) { Decimal deliver = toDeliver; if (deliver.CompareTo(onHand) > 0) { deliver = onHand; } log.Fine("Available - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + ", Delivering=" + deliver + " - " + line); // CreateLine(order, line, deliver, storages, false); } // Force else if (MOrder.DELIVERYRULE_Force.Equals(order.GetDeliveryRule())) { Decimal deliver = toDeliver; log.Fine("Force - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + ", Delivering=" + deliver + " - " + line); // CreateLine(order, line, deliver, storages, true); } // Manual else if (MOrder.DELIVERYRULE_Manual.Equals(order.GetDeliveryRule())) { log.Fine("Manual - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ") - " + line); } else { log.Fine("Failed: " + order.GetDeliveryRule() + " - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + " - " + line); } } // for all order lines // Complete Order successful if (completeOrder && MOrder.DELIVERYRULE_CompleteOrder.Equals(order.GetDeliveryRule())) { for (int i = 0; i < lines.Length; i++) { MOrderLine line = lines[i]; if (line.GetM_Warehouse_ID() != _M_Warehouse_ID) { continue; } MProduct product = line.GetProduct(); Decimal toDeliver = Decimal.Subtract(line.GetQtyOrdered(), line.GetQtyDelivered()); // MStorage[] storages = null; if (product != null && product.IsStocked()) { MProductCategory pc = MProductCategory.Get(order.GetCtx(), product.GetM_Product_Category_ID()); String MMPolicy = pc.GetMMPolicy(); if (MMPolicy == null || MMPolicy.Length == 0) { MMPolicy = client.GetMMPolicy(); } // storages = GetStorages(line.GetM_Warehouse_ID(), line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), product.GetM_AttributeSet_ID(), line.GetM_AttributeSetInstance_ID() == 0, (DateTime?)minGuaranteeDate, MClient.MMPOLICY_FiFo.Equals(MMPolicy)); } // CreateLine(order, line, toDeliver, storages, false); } } _line += 1000; } // while order } catch (Exception e) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, _sql, e); } finally { if (idr != null) { idr.Close(); } dt = null; } CompleteShipment(); return("@Created@ = " + _created); }
/// <summary> /// Create 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); }