/// <summary> /// Process Confirmation Line. /// - Update InOut Line /// </summary> /// <param name="isSOTrx">sales order</param> /// <param name="confirmType">type</param> /// <returns>success</returns> public Boolean ProcessLine(bool isSOTrx, String confirmType) { MInOutLine line = GetLine(); // Customer if (MInOutConfirm.CONFIRMTYPE_CustomerConfirmation.Equals(confirmType)) { line.SetConfirmedQty(GetConfirmedQty()); } // Drop Ship else if (MInOutConfirm.CONFIRMTYPE_DropShipConfirm.Equals(confirmType)) { } // Pick or QA else if (MInOutConfirm.CONFIRMTYPE_PickQAConfirm.Equals(confirmType)) { line.SetTargetQty(GetTargetQty()); line.SetMovementQty(GetConfirmedQty()); // Entered NOT changed line.SetPickedQty(GetConfirmedQty()); // line.SetScrappedQty(GetScrappedQty()); } // Ship or Receipt else if (MInOutConfirm.CONFIRMTYPE_ShipReceiptConfirm.Equals(confirmType)) { line.SetTargetQty(GetTargetQty()); Decimal qty = GetConfirmedQty(); Boolean isReturnTrx = line.GetParent().IsReturnTrx(); /* In PO receipts and SO Returns, we have the responsibility * for scrapped quantity */ if ((!isSOTrx && !isReturnTrx) || (isSOTrx && isReturnTrx)) { qty = Decimal.Add(qty, GetScrappedQty()); } line.SetMovementQty(qty); // Entered NOT changed // line.SetScrappedQty(GetScrappedQty()); // vikas 12/28/2015 Mantis Issue (0000335) line.SetConfirmedQty(GetConfirmedQty()); } // Vendor else if (MInOutConfirm.CONFIRMTYPE_VendorConfirmation.Equals(confirmType)) { line.SetConfirmedQty(GetConfirmedQty()); } return(line.Save(Get_TrxName())); }
/** * Create Invoice Line from Shipment * @param order order * @param ship shipment header * @param sLine shipment line */ private void CreateLine(MOrder order, MInOut ship, MInOutLine sLine) { if (_invoice == null) { _invoice = new MInvoice(order, 0, _DateInvoiced); if (!_invoice.Save()) { throw new Exception("Could not create Invoice (s)"); } } #region Comment Create Shipment Comment Line // Create Shipment Comment Line //if (_ship == null // || _ship.GetM_InOut_ID() != ship.GetM_InOut_ID()) //{ // MDocType dt = MDocType.Get(GetCtx(), ship.GetC_DocType_ID()); // if (_bp == null || _bp.GetC_BPartner_ID() != ship.GetC_BPartner_ID()) // { // _bp = new MBPartner(GetCtx(), ship.GetC_BPartner_ID(), Get_TrxName()); // } // // Reference: Delivery: 12345 - 12.12.12 // MClient client = MClient.Get(GetCtx(), order.GetAD_Client_ID()); // String AD_Language = client.GetAD_Language(); // if (client.IsMultiLingualDocument() && _bp.GetAD_Language() != null) // { // AD_Language = _bp.GetAD_Language(); // } // if (AD_Language == null) // { // // MessageBox.Show("Set base Language"); // //AD_Language = Language.getBaseAD_Language(); // } // //java.text.SimpleDateFormat format = DisplayType.getDateFormat // // (DisplayType.Date, Language.getLanguage(AD_Language)); // //String reference = dt.GetPrintName(_bp.GetAD_Language()) // // + ": " + ship.GetDocumentNo() // // + " - " + format.format(ship.GetMovementDate()); // String reference = dt.GetPrintName(_bp.GetAD_Language()) // + ": " + ship.GetDocumentNo() // + " - " + ship.GetMovementDate(); // _ship = ship; // // // MInvoiceLine line = new MInvoiceLine(_invoice); // line.SetIsDescription(true); // line.SetDescription(reference); // line.SetLine(_line + sLine.GetLine() - 2); // if (!line.Save()) // { // throw new Exception("Could not create Invoice Comment Line (sh)"); // } // // Optional Ship Address if not Bill Address // if (order.GetBill_Location_ID() != ship.GetC_BPartner_Location_ID()) // { // MLocation addr = MLocation.GetBPLocation(GetCtx(), ship.GetC_BPartner_Location_ID(), null); // line = new MInvoiceLine(_invoice); // line.SetIsDescription(true); // line.SetDescription(addr.ToString()); // line.SetLine(_line + sLine.GetLine() - 1); // if (!line.Save()) // { // throw new Exception("Could not create Invoice Comment Line 2 (sh)"); // } // } //} #endregion // MInvoiceLine line1 = new MInvoiceLine(_invoice); line1.SetShipLine(sLine); line1.SetQtyEntered(sLine.GetQtyEntered()); line1.SetQtyInvoiced(sLine.GetMovementQty()); line1.SetLine(_line + sLine.GetLine()); line1.SetM_AttributeSetInstance_ID(sLine.GetM_AttributeSetInstance_ID()); if (!line1.Save()) { throw new Exception("Could not create Invoice Line (s)"); } // Link sLine.SetIsInvoiced(true); if (!sLine.Save()) { throw new Exception("Could not update Shipment Line"); } log.Fine(line1.ToString()); }
public bool SetProductQty(int recordID, string keyColName, List <string> product, List <string> attribute, List <string> qty, List <string> qtybook, List <string> oline_ID, int ordID, List <string> locID, int lineID, VAdvantage.Utility.Ctx ctx) { if (keyColName.ToUpper().Trim() == "C_ORDER_ID") { MOrder ord = new MOrder(ctx, recordID, null); for (int i = 0; i < product.Count; i++) { MOrderLine oline = new MOrderLine(ctx, lineID, null); oline.SetAD_Client_ID(ord.GetAD_Client_ID()); oline.SetAD_Org_ID(ord.GetAD_Org_ID()); oline.SetM_Product_ID(Util.GetValueOfInt(product[i])); oline.SetQty(Util.GetValueOfDecimal(qty[i])); oline.SetC_Order_ID(recordID); if (Util.GetValueOfInt(attribute[i]) != 0) { oline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i])); } if (!ord.IsSOTrx()) { MProduct pro = new MProduct(ctx, oline.GetM_Product_ID(), null); String qryUom = "SELECT vdr.C_UOM_ID FROM M_Product p LEFT JOIN M_Product_Po vdr ON p.M_Product_ID= vdr.M_Product_ID WHERE p.M_Product_ID=" + oline.GetM_Product_ID() + " AND vdr.C_BPartner_ID = " + ord.GetC_BPartner_ID(); int uom = Util.GetValueOfInt(DB.ExecuteScalar(qryUom)); if (pro.GetC_UOM_ID() != 0) { if (pro.GetC_UOM_ID() != uom && uom != 0) { decimal?Res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND M_Product_ID= " + oline.GetM_Product_ID() + " AND IsActive='Y'")); if (Res > 0) { oline.SetQtyEntered(oline.GetQtyEntered() * Res); //OrdQty = MUOMConversion.ConvertProductTo(GetCtx(), _M_Product_ID, UOM, OrdQty); } else { decimal?res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND IsActive='Y'")); if (res > 0) { oline.SetQtyEntered(oline.GetQtyEntered() * res); //OrdQty = MUOMConversion.Convert(GetCtx(), prdUOM, UOM, OrdQty); } } oline.SetC_UOM_ID(uom); } else { oline.SetC_UOM_ID(pro.GetC_UOM_ID()); } } } if (!oline.Save()) { } } } else if (keyColName.ToUpper().Trim() == "C_INVOICE_ID") { MInvoice inv = new MInvoice(ctx, recordID, null); for (int i = 0; i < product.Count; i++) { MInvoiceLine invline = new MInvoiceLine(ctx, lineID, null); invline.SetAD_Client_ID(inv.GetAD_Client_ID()); invline.SetAD_Org_ID(inv.GetAD_Org_ID()); invline.SetM_Product_ID(Util.GetValueOfInt(product[i])); invline.SetQty(Util.GetValueOfDecimal(qty[i])); invline.SetC_Invoice_ID(recordID); if (Util.GetValueOfInt(attribute[i]) != 0) { invline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i])); } if (!inv.IsSOTrx()) { MProduct pro = new MProduct(ctx, invline.GetM_Product_ID(), null); String qryUom = "SELECT vdr.C_UOM_ID FROM M_Product p LEFT JOIN M_Product_Po vdr ON p.M_Product_ID= vdr.M_Product_ID WHERE p.M_Product_ID=" + invline.GetM_Product_ID() + " AND vdr.C_BPartner_ID = " + inv.GetC_BPartner_ID(); int uom = Util.GetValueOfInt(DB.ExecuteScalar(qryUom)); if (pro.GetC_UOM_ID() != 0) { if (pro.GetC_UOM_ID() != uom && uom != 0) { decimal?Res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND M_Product_ID= " + invline.GetM_Product_ID() + " AND IsActive='Y'")); if (Res > 0) { invline.SetQtyEntered(invline.GetQtyEntered() * Res); //OrdQty = MUOMConversion.ConvertProductTo(GetCtx(), _M_Product_ID, UOM, OrdQty); } else { decimal?res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND IsActive='Y'")); if (res > 0) { invline.SetQtyEntered(invline.GetQtyEntered() * res); //OrdQty = MUOMConversion.Convert(GetCtx(), prdUOM, UOM, OrdQty); } } invline.SetC_UOM_ID(uom); } else { invline.SetC_UOM_ID(pro.GetC_UOM_ID()); } } } if (!invline.Save()) { } } } else if (keyColName.ToUpper().Trim() == "M_INOUT_ID") { MInOut inv = new MInOut(ctx, recordID, null); if (ordID > 0) { inv.SetC_Order_ID(ordID); } if (inv.Save()) { for (int i = 0; i < product.Count; i++) { MInOutLine ioline = new MInOutLine(ctx, lineID, null); ioline.SetAD_Client_ID(inv.GetAD_Client_ID()); ioline.SetAD_Org_ID(inv.GetAD_Org_ID()); ioline.SetM_Product_ID(Util.GetValueOfInt(product[i])); ioline.SetQty(Util.GetValueOfDecimal(qty[i])); ioline.SetM_InOut_ID(recordID); ioline.SetC_OrderLine_ID(Util.GetValueOfInt(oline_ID[i])); ioline.SetM_Locator_ID(Util.GetValueOfInt(locID[i])); if (Util.GetValueOfInt(attribute[i]) != 0) { ioline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i])); } if (!inv.IsSOTrx()) { MProduct pro = new MProduct(ctx, ioline.GetM_Product_ID(), null); String qryUom = "SELECT vdr.C_UOM_ID FROM M_Product p LEFT JOIN M_Product_Po vdr ON p.M_Product_ID= vdr.M_Product_ID WHERE p.M_Product_ID=" + ioline.GetM_Product_ID() + " AND vdr.C_BPartner_ID = " + inv.GetC_BPartner_ID(); int uom = Util.GetValueOfInt(DB.ExecuteScalar(qryUom)); if (pro.GetC_UOM_ID() != 0) { if (pro.GetC_UOM_ID() != uom && uom != 0) { decimal?Res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND M_Product_ID= " + ioline.GetM_Product_ID() + " AND IsActive='Y'")); if (Res > 0) { ioline.SetQtyEntered(ioline.GetQtyEntered() * Res); //OrdQty = MUOMConversion.ConvertProductTo(GetCtx(), _M_Product_ID, UOM, OrdQty); } else { decimal?res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND IsActive='Y'")); if (res > 0) { ioline.SetQtyEntered(ioline.GetQtyEntered() * res); //OrdQty = MUOMConversion.Convert(GetCtx(), prdUOM, UOM, OrdQty); } } ioline.SetC_UOM_ID(uom); } else { ioline.SetC_UOM_ID(pro.GetC_UOM_ID()); } } } if (!ioline.Save()) { } } } } else if (keyColName.ToUpper().Trim() == "M_PACKAGE_ID") { MPackage pkg = new MPackage(ctx, recordID, null); for (int i = 0; i < product.Count; i++) { MPackageLine mline = new MPackageLine(ctx, lineID, null); mline.SetAD_Client_ID(pkg.GetAD_Client_ID()); mline.SetAD_Org_ID(pkg.GetAD_Org_ID()); mline.SetM_Product_ID(Util.GetValueOfInt(product[i])); mline.SetQty(Util.GetValueOfDecimal(qty[i])); if (Util.GetValueOfInt(oline_ID[i]) > 0) { mline.SetM_MovementLine_ID(Util.GetValueOfInt(oline_ID[i])); MMovementLine mov = new MMovementLine(ctx, Util.GetValueOfInt(oline_ID[i]), null); mline.SetDTD001_TotalQty(mov.GetMovementQty()); } if (Util.GetValueOfInt(attribute[i]) != 0) { mline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i])); } mline.SetM_Package_ID(recordID); if (!mline.Save()) { } } } else if (keyColName.ToUpper().Trim() == "M_INVENTORY_ID") { MInventory inv = new MInventory(ctx, recordID, null); for (int i = 0; i < product.Count; i++) { MInventoryLine invline = new MInventoryLine(ctx, lineID, null); invline.SetAD_Client_ID(inv.GetAD_Client_ID()); invline.SetAD_Org_ID(inv.GetAD_Org_ID()); invline.SetM_Locator_ID(Util.GetValueOfInt(locID[i])); invline.SetM_Product_ID(Util.GetValueOfInt(product[i])); invline.SetQtyCount(Util.GetValueOfDecimal(qty[i])); invline.SetQtyBook(Util.GetValueOfDecimal(qtybook[i])); invline.SetAsOnDateCount(Util.GetValueOfDecimal(qty[i])); invline.SetOpeningStock(Util.GetValueOfDecimal(qtybook[i])); invline.SetM_Inventory_ID(recordID); if (Util.GetValueOfInt(attribute[i]) != 0) { invline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i])); } else { invline.SetM_AttributeSetInstance_ID(0); } if (!invline.Save()) { } } } return(true); }
/// <summary> /// Create Shipment /// </summary> /// <returns>info</returns> protected override String DoIt() { //log.info("C_Invoice_ID=" + _C_Invoice_ID // + ", M_Warehouse_ID=" + _M_Warehouse_ID // + ", C_DocType_ID=" + _C_DocType_ID); if (_C_Invoice_ID == 0) { throw new ArgumentException("@NotFound@ @C_Invoice_ID@"); } if (_M_Warehouse_ID == 0) { throw new ArgumentException("@NotFound@ @M_Warehouse_ID@"); } // MInvoice invoice = new MInvoice(GetCtx(), _C_Invoice_ID, Get_Trx()); if (invoice.Get_ID() == 0) { throw new ArgumentException("@NotFound@ @C_Invoice_ID@"); } if (!MInvoice.DOCSTATUS_Completed.Equals(invoice.GetDocStatus())) { throw new ArgumentException("@InvoiceCreateDocNotCompleted@"); } MDocType dt = MDocType.Get(GetCtx(), _C_DocType_ID); if (invoice.IsSOTrx() != dt.IsSOTrx() || invoice.IsReturnTrx() != dt.IsReturnTrx()) { throw new ArgumentException("@C_DocType_ID@ <> @C_Invoice_ID@"); } //*****************************Vikas 1 Dec 2015 ********************************* //Case Msg Not Showing Proper MInOut ship = null; MOrder ord = new MOrder(GetCtx(), invoice.GetC_Order_ID(), null); if (ord.GetC_BPartner_ID() > 0) { ship = new MInOut(invoice, _C_DocType_ID, null, _M_Warehouse_ID); // Change by Mohit Asked by Amardeep sir 02/03/2016 ship.SetPOReference(invoice.GetPOReference()); // End if (!ship.Save()) { return(GetRetrievedError(ship, "@SaveError@ Receipt")); // throw new ArgumentException("@SaveError@ Receipt"); } } else { return(GetRetrievedError(ship, "InvoiceNotLinkedWithPO")); //throw new ArgumentException("@InvoiceNotLinkedWithPO@"); } /* * MInOut ship = new MInOut(invoice, _C_DocType_ID, null, _M_Warehouse_ID); * if (!ship.Save()) * { * throw new ArgumentException("@SaveError@ Receipt"); * } */ //************************END***************************************** MInvoiceLine[] invoiceLines = invoice.GetLines(false); for (int i = 0; i < invoiceLines.Length; i++) { MInvoiceLine invoiceLine = invoiceLines[i]; MProduct product = invoiceLine.GetProduct(); // Nothing to Deliver // Get the lines of Invoice based on the setting taken on Tenant to allow non item Product if (Util.GetValueOfString(GetCtx().GetContext("$AllowNonItem")).Equals("N") && ((product != null && product.GetProductType() != MProduct.PRODUCTTYPE_Item) || invoiceLine.GetC_Charge_ID() != 0)) { continue; } MInOutLine sLine = new MInOutLine(ship); //JID_1679 Generate Receipt from Invoice(Vendor) for remaining quantity //decimal movementqty = 0; //if (invoiceLine.GetC_OrderLine_ID() != 0) //{ // decimal? res = 0; // movementqty = Util.GetValueOfDecimal(DB.ExecuteScalar(@" select (QtyOrdered-sum(MovementQty)) from C_OrderLine ol Inner join M_InOutLine il on il.C_orderline_ID= ol.C_Orderline_Id " // + " WHERE il.C_OrderLine_ID =" + invoiceLine.GetC_OrderLine_ID() + "group by QtyOrdered", null, Get_Trx())); // // in case of partial receipt // if (invoiceLine.GetQtyInvoiced() > movementqty && movementqty != 0) // { // if (product.GetC_UOM_ID() != invoiceLine.GetC_UOM_ID()) // { // res = MUOMConversion.ConvertProductTo(GetCtx(), product.GetM_Product_ID(), invoiceLine.GetC_UOM_ID(), movementqty); // } // sLine.SetInvoiceLine(invoiceLine, 0, // Locator // invoice.IsSOTrx() ? (movementqty) : Env.ZERO); // sLine.SetQtyEntered(res == 0 ? (movementqty) : res); // sLine.SetMovementQty(movementqty); // } // // if QtyInvoiced is less or No Material receipt is found against the order // else // { // sLine.SetInvoiceLine(invoiceLine, 0, // Locator // invoice.IsSOTrx() ? invoiceLine.GetQtyInvoiced() : Env.ZERO); // sLine.SetQtyEntered(invoiceLine.GetQtyEntered()); // sLine.SetMovementQty(invoiceLine.GetQtyInvoiced()); // } //} //else //{ sLine.SetInvoiceLine(invoiceLine, 0, // Locator invoice.IsSOTrx() ? invoiceLine.GetQtyInvoiced() : Env.ZERO); sLine.SetQtyEntered(invoiceLine.GetQtyEntered()); sLine.SetMovementQty(invoiceLine.GetQtyInvoiced()); //} if (invoice.IsCreditMemo()) { sLine.SetQtyEntered(Decimal.Negate(sLine.GetQtyEntered())); //.negate()); sLine.SetMovementQty(Decimal.Negate(sLine.GetMovementQty())); //.negate()); } if (!sLine.Save()) { ship.Get_Trx().Rollback(); //if (movementqty == 0) //{ // _processMsg += ", LineNo: " + invoiceLine.GetLine() + Msg.GetMsg(GetCtx(), "MRIsAlreadyCreated"); // return _processMsg; //} //else //{ return(GetRetrievedError(sLine, "@SaveError@ @M_InOutLine_ID@")); //} // throw new ArgumentException("@SaveError@ @M_InOutLine_ID@"); } invoiceLine.SetM_InOutLine_ID(sLine.GetM_InOutLine_ID()); // _processMsg+= ", LineNo: "+invoiceLine.GetLine()+Msg.GetMsg(GetCtx(), "MRCreatedWithDocNo" + ship.GetDocumentNo()); if (!invoiceLine.Save()) { return(GetRetrievedError(invoiceLine, "@SaveError@ @C_InvoiceLine_ID@")); //throw new ArgumentException("@SaveError@ @C_InvoiceLine_ID@"); } } return(ship.GetDocumentNo()); }
/// <summary> /// Create Invoice Line from Shipment /// </summary> /// <param name="order">order</param> /// <param name="ship">shipment header</param> /// <param name="sLine">shipment line</param> private void CreateLine(MOrder order, MInOut ship, MInOutLine sLine) { if (_invoice == null) { _invoice = new MInvoice(order, 0, _DateInvoiced); int _CountVA009 = Env.IsModuleInstalled("VA009_") ? 1 : 0; if (_CountVA009 > 0) { int _PaymentMethod_ID = order.GetVA009_PaymentMethod_ID(); // during consolidation, payment method need to set that is defined on selected business partner. // If not defined on BP then it will set from order // during sale cycle -- VA009_PaymentMethod_ID // during purchase cycle -- VA009_PO_PaymentMethod_ID int bpPamentMethod_ID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT " + (order.IsSOTrx() ? " VA009_PaymentMethod_ID " : " VA009_PO_PaymentMethod_ID ") + @" FROM C_BPartner WHERE C_BPartner_ID = " + order.GetC_BPartner_ID(), null, Get_Trx())); if (_ConsolidateDocument && bpPamentMethod_ID != 0) { _PaymentMethod_ID = bpPamentMethod_ID; } if (_PaymentMethod_ID > 0) { _invoice.SetVA009_PaymentMethod_ID(_PaymentMethod_ID); } } int _CountVA026 = Env.IsModuleInstalled("VA026_") ? 1 : 0; if (_CountVA026 > 0) { _invoice.SetVA026_LCDetail_ID(order.GetVA026_LCDetail_ID()); } // Added by Bharat on 29 Jan 2018 to set Inco Term from Order if (_invoice.Get_ColumnIndex("C_IncoTerm_ID") > 0) { _invoice.SetC_IncoTerm_ID(order.GetC_IncoTerm_ID()); } if (Env.IsModuleInstalled("VA077_")) { //.setva077 _invoice.Set_Value("VA077_AdditionalAnnualCharge", order.Get_Value("VA077_AdditionalAnnualCharge")); _invoice.Set_Value("VA077_ChangeStartDate", order.Get_Value("VA077_ChangeStartDate")); _invoice.Set_Value("VA077_ContractCPEndDate", order.Get_Value("VA077_ContractCPEndDate")); _invoice.Set_Value("VA077_ContractCPStartDate", order.Get_Value("VA077_ContractCPStartDate")); _invoice.Set_Value("VA077_HistoricContractDate", order.Get_Value("VA077_HistoricContractDate")); _invoice.Set_Value("VA077_IsLegalEntity", order.Get_Value("VA077_IsLegalEntity")); _invoice.Set_Value("VA077_MarginPercent", order.Get_Value("VA077_MarginPercent")); _invoice.Set_Value("VA077_NewAnnualContractTotal", order.Get_Value("VA077_NewAnnualContractTotal")); _invoice.Set_Value("VA077_OldAnnualContractTotal", order.Get_Value("VA077_OldAnnualContractTotal")); _invoice.Set_Value("VA077_PartialAmtCatchUp", order.Get_Value("VA077_PartialAmtCatchUp")); _invoice.Set_Value("VA077_SalesCoWorker", order.Get_Value("VA077_SalesCoWorker")); _invoice.Set_Value("VA077_SalesCoWorkerPer", order.Get_Value("VA077_SalesCoWorkerPer")); _invoice.Set_Value("VA077_TotalMarginAmt", order.Get_Value("VA077_TotalMarginAmt")); _invoice.Set_Value("VA077_TotalPurchaseAmt", order.Get_Value("VA077_TotalPurchaseAmt")); _invoice.Set_Value("VA077_TotalSalesAmt", order.Get_Value("VA077_TotalSalesAmt")); } if (!_invoice.Save()) { ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Could not create Invoice (s). " + pp.GetName()); } throw new Exception("Could not create Invoice (s)"); } } #region Comment Create Shipment Comment Line // Create Shipment Comment Line //if (_ship == null // || _ship.GetM_InOut_ID() != ship.GetM_InOut_ID()) //{ // MDocType dt = MDocType.Get(GetCtx(), ship.GetC_DocType_ID()); // if (_bp == null || _bp.GetC_BPartner_ID() != ship.GetC_BPartner_ID()) // { // _bp = new MBPartner(GetCtx(), ship.GetC_BPartner_ID(), Get_TrxName()); // } // // Reference: Delivery: 12345 - 12.12.12 // MClient client = MClient.Get(GetCtx(), order.GetAD_Client_ID()); // String AD_Language = client.GetAD_Language(); // if (client.IsMultiLingualDocument() && _bp.GetAD_Language() != null) // { // AD_Language = _bp.GetAD_Language(); // } // if (AD_Language == null) // { // // MessageBox.Show("Set base Language"); // //AD_Language = Language.getBaseAD_Language(); // } // //java.text.SimpleDateFormat format = DisplayType.getDateFormat // // (DisplayType.Date, Language.getLanguage(AD_Language)); // //String reference = dt.GetPrintName(_bp.GetAD_Language()) // // + ": " + ship.GetDocumentNo() // // + " - " + format.format(ship.GetMovementDate()); // String reference = dt.GetPrintName(_bp.GetAD_Language()) // + ": " + ship.GetDocumentNo() // + " - " + ship.GetMovementDate(); // _ship = ship; // // // MInvoiceLine line = new MInvoiceLine(_invoice); // line.SetIsDescription(true); // line.SetDescription(reference); // line.SetLine(_line + sLine.GetLine() - 2); // if (!line.Save()) // { // throw new Exception("Could not create Invoice Comment Line (sh)"); // } // // Optional Ship Address if not Bill Address // if (order.GetBill_Location_ID() != ship.GetC_BPartner_Location_ID()) // { // MLocation addr = MLocation.GetBPLocation(GetCtx(), ship.GetC_BPartner_Location_ID(), null); // line = new MInvoiceLine(_invoice); // line.SetIsDescription(true); // line.SetDescription(addr.ToString()); // line.SetLine(_line + sLine.GetLine() - 1); // if (!line.Save()) // { // throw new Exception("Could not create Invoice Comment Line 2 (sh)"); // } // } //} #endregion // MInvoiceLine line1 = new MInvoiceLine(_invoice); line1.SetShipLine(sLine); line1.SetQtyEntered(sLine.GetQtyEntered()); line1.SetQtyInvoiced(sLine.GetMovementQty()); line1.SetLine(_line + sLine.GetLine()); line1.SetM_AttributeSetInstance_ID(sLine.GetM_AttributeSetInstance_ID()); if (sLine.GetA_Asset_ID() > 0) { line1.SetA_Asset_ID(sLine.GetA_Asset_ID()); if (line1.Get_ColumnIndex("VAFAM_AssetCost") > 0) { int PAcctSchema_ID = 0; int pCurrency_ID = 0; MAcctSchema as1 = MClient.Get(GetCtx(), GetAD_Client_ID()).GetAcctSchema(); if (as1 != null) { PAcctSchema_ID = as1.GetC_AcctSchema_ID(); pCurrency_ID = as1.GetC_Currency_ID(); } decimal LineNetAmt = Decimal.Multiply(line1.GetPriceActual(), line1.GetQtyEntered()); decimal AssetCost = GetAssetCost(sLine.GetA_Asset_ID(), sLine.GetM_Product_ID(), PAcctSchema_ID); AssetCost = Decimal.Multiply(AssetCost, line1.GetQtyEntered()); if (LineNetAmt > 0) { LineNetAmt = MConversionRate.Convert(GetCtx(), LineNetAmt, _invoice.GetC_Currency_ID(), pCurrency_ID, _invoice.GetAD_Client_ID(), _invoice.GetAD_Org_ID()); } decimal Diff = LineNetAmt - AssetCost; line1.Set_Value("VAFAM_AssetCost", AssetCost); line1.Set_Value("VAFAM_Difference", Diff); } } if (Env.IsModuleInstalled("VA077_")) { //invoice line line1.Set_Value("VA077_CNAutodesk", sLine.Get_Value("VA077_CNAutodesk")); line1.Set_Value("VA077_Duration", sLine.Get_Value("VA077_Duration")); line1.Set_Value("VA077_MarginAmt", sLine.Get_Value("VA077_MarginAmt")); line1.Set_Value("VA077_MarginPercent", sLine.Get_Value("VA077_MarginPercent")); line1.Set_Value("VA077_OldSN", sLine.Get_Value("VA077_OldSN")); line1.Set_Value("VA077_ProductInfo", sLine.Get_Value("VA077_ProductInfo")); line1.Set_Value("VA077_PurchasePrice", sLine.Get_Value("VA077_PurchasePrice")); line1.Set_Value("VA077_RegEmail", sLine.Get_Value("VA077_RegEmail")); line1.Set_Value("VA077_SerialNo", sLine.Get_Value("VA077_SerialNo")); line1.Set_Value("VA077_UpdateFromVersn", sLine.Get_Value("VA077_UpdateFromVersn")); line1.Set_Value("VA077_UserRef_ID", sLine.Get_Value("VA077_UserRef_ID")); line1.Set_Value("VA077_EndDate", sLine.Get_Value("VA077_EndDate")); line1.Set_Value("VA077_StartDate", sLine.Get_Value("VA077_StartDate")); } if (!line1.Save()) { ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Could not create Invoice Line (s). " + pp.GetName()); } throw new Exception("Could not create Invoice Line (s)"); } // Link sLine.SetIsInvoiced(true); if (!sLine.Save()) { ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Could not update Shipment Line. " + pp.GetName()); } throw new Exception("Could not update Shipment Line"); } log.Fine(line1.ToString()); }
/// <summary> /// Create Shipment /// </summary> /// <returns>info</returns> protected override String DoIt() { //log.info("C_Invoice_ID=" + _C_Invoice_ID // + ", M_Warehouse_ID=" + _M_Warehouse_ID // + ", C_DocType_ID=" + _C_DocType_ID); if (_C_Invoice_ID == 0) { throw new ArgumentException("@NotFound@ @C_Invoice_ID@"); } if (_M_Warehouse_ID == 0) { throw new ArgumentException("@NotFound@ @M_Warehouse_ID@"); } // MInvoice invoice = new MInvoice(GetCtx(), _C_Invoice_ID, null); if (invoice.Get_ID() == 0) { throw new ArgumentException("@NotFound@ @C_Invoice_ID@"); } if (!MInvoice.DOCSTATUS_Completed.Equals(invoice.GetDocStatus())) { throw new ArgumentException("@InvoiceCreateDocNotCompleted@"); } MDocType dt = MDocType.Get(GetCtx(), _C_DocType_ID); if (invoice.IsSOTrx() != dt.IsSOTrx() || invoice.IsReturnTrx() != dt.IsReturnTrx()) { throw new ArgumentException("@C_DocType_ID@ <> @C_Invoice_ID@"); } //*****************************Vikas 1 Dec 2015 ********************************* //Case Msg Not Showing Proper MInOut ship = null; MOrder ord = new MOrder(GetCtx(), invoice.GetC_Order_ID(), null); if (ord.GetC_BPartner_ID() > 0) { ship = new MInOut(invoice, _C_DocType_ID, null, _M_Warehouse_ID); // Change by Mohit Asked by Amardeep sir 02/03/2016 ship.SetPOReference(invoice.GetPOReference()); // End if (!ship.Save()) { return(GetRetrievedError(ship, "@SaveError@ Receipt")); // throw new ArgumentException("@SaveError@ Receipt"); } } else { return(GetRetrievedError(ship, "InvoiceNotLinkedWithPO")); //throw new ArgumentException("@InvoiceNotLinkedWithPO@"); } /* * MInOut ship = new MInOut(invoice, _C_DocType_ID, null, _M_Warehouse_ID); * if (!ship.Save()) * { * throw new ArgumentException("@SaveError@ Receipt"); * } */ //************************END***************************************** MInvoiceLine[] invoiceLines = invoice.GetLines(false); for (int i = 0; i < invoiceLines.Length; i++) { MInvoiceLine invoiceLine = invoiceLines[i]; MProduct product = invoiceLine.GetProduct(); // Nothing to Deliver // Get the lines of Invoice based on the setting taken on Tenant to allow non item Product if (Util.GetValueOfString(GetCtx().GetContext("$AllowNonItem")).Equals("N") && ((product != null && product.GetProductType() != MProduct.PRODUCTTYPE_Item) || invoiceLine.GetC_Charge_ID() != 0)) { continue; } MInOutLine sLine = new MInOutLine(ship); sLine.SetInvoiceLine(invoiceLine, 0, // Locator invoice.IsSOTrx() ? invoiceLine.GetQtyInvoiced() : Env.ZERO); sLine.SetQtyEntered(invoiceLine.GetQtyEntered()); sLine.SetMovementQty(invoiceLine.GetQtyInvoiced()); if (invoice.IsCreditMemo()) { sLine.SetQtyEntered(Decimal.Negate(sLine.GetQtyEntered())); //.negate()); sLine.SetMovementQty(Decimal.Negate(sLine.GetMovementQty())); //.negate()); } if (!sLine.Save()) { return(GetRetrievedError(sLine, "@SaveError@ @M_InOutLine_ID@")); //throw new ArgumentException("@SaveError@ @M_InOutLine_ID@"); } // invoiceLine.SetM_InOutLine_ID(sLine.GetM_InOutLine_ID()); if (!invoiceLine.Save()) { return(GetRetrievedError(invoiceLine, "@SaveError@ @C_InvoiceLine_ID@")); //throw new ArgumentException("@SaveError@ @C_InvoiceLine_ID@"); } } return(ship.GetDocumentNo()); }
/// <summary> /// Create Shipment /// </summary> /// <returns>info</returns> protected override String DoIt() { //log.info("C_Invoice_ID=" + _C_Invoice_ID // + ", M_Warehouse_ID=" + _M_Warehouse_ID // + ", C_DocType_ID=" + _C_DocType_ID); if (_C_Invoice_ID == 0) { throw new ArgumentException("@NotFound@ @C_Invoice_ID@"); } if (_M_Warehouse_ID == 0) { throw new ArgumentException("@NotFound@ @M_Warehouse_ID@"); } // MInvoice invoice = new MInvoice(GetCtx(), _C_Invoice_ID, null); if (invoice.Get_ID() == 0) { throw new ArgumentException("@NotFound@ @C_Invoice_ID@"); } if (!MInvoice.DOCSTATUS_Completed.Equals(invoice.GetDocStatus())) { throw new ArgumentException("@InvoiceCreateDocNotCompleted@"); } MDocType dt = MDocType.Get(GetCtx(), _C_DocType_ID); if (invoice.IsSOTrx() != dt.IsSOTrx() || invoice.IsReturnTrx() != dt.IsReturnTrx()) { throw new ArgumentException("@C_DocType_ID@ <> @C_Invoice_ID@"); } // MInOut ship = new MInOut(invoice, _C_DocType_ID, null, _M_Warehouse_ID); if (!ship.Save()) { throw new ArgumentException("@SaveError@ Receipt"); } // MInvoiceLine[] invoiceLines = invoice.GetLines(false); for (int i = 0; i < invoiceLines.Length; i++) { MInvoiceLine invoiceLine = invoiceLines[i]; MInOutLine sLine = new MInOutLine(ship); sLine.SetInvoiceLine(invoiceLine, 0, // Locator invoice.IsSOTrx() ? invoiceLine.GetQtyInvoiced() : Env.ZERO); sLine.SetQtyEntered(invoiceLine.GetQtyEntered()); sLine.SetMovementQty(invoiceLine.GetQtyInvoiced()); if (invoice.IsCreditMemo()) { sLine.SetQtyEntered(Decimal.Negate(sLine.GetQtyEntered())); //.negate()); sLine.SetMovementQty(Decimal.Negate(sLine.GetMovementQty())); //.negate()); } if (!sLine.Save()) { throw new ArgumentException("@SaveError@ @M_InOutLine_ID@"); } // invoiceLine.SetM_InOutLine_ID(sLine.GetM_InOutLine_ID()); if (!invoiceLine.Save()) { throw new ArgumentException("@SaveError@ @C_InvoiceLine_ID@"); } } return(ship.GetDocumentNo()); }
/** * Split Shipment into confirmed and dispute * @param original original shipment * @param C_DocType_ID target DocType * @param confirmLines confirm lines */ private void SplitInOut(MInOut original, int C_DocType_ID, MInOutLineConfirm[] confirmLines) { MInOut split = new MInOut(original, C_DocType_ID, original.GetMovementDate()); split.AddDescription("Splitted from " + original.GetDocumentNo()); split.SetIsInDispute(true); // new 13 jan int _count = Util.GetValueOfInt(DB.ExecuteScalar("SELECT count(*) FROM AD_Column clm INNER JOIN ad_table tbl on (tbl.ad_table_id=clm.ad_table_id) where tbl.tablename='M_InOutLineConfirm' and clm.columnname = 'M_Locator_ID' ")); //nnayak : Change for bug 1431337 split.SetRef_InOut_ID(original.Get_ID()); if (!split.Save(Get_TrxName())) { throw new Exception("Cannot save Split"); } original.AddDescription("Split: " + split.GetDocumentNo()); if (!original.Save(Get_TrxName())) { throw new Exception("Cannot update original Shipment"); } // Go through confirmations for (int i = 0; i < confirmLines.Length; i++) { MInOutLineConfirm confirmLine = confirmLines[i]; Decimal differenceQty = confirmLine.GetDifferenceQty(); if (differenceQty.CompareTo(Env.ZERO) == 0) { continue; } // MInOutLine oldLine = confirmLine.GetLine(); log.Fine("Qty=" + differenceQty + ", Old=" + oldLine); // MInOutLine splitLine = new MInOutLine(split); splitLine.SetC_OrderLine_ID(oldLine.GetC_OrderLine_ID()); splitLine.SetC_UOM_ID(oldLine.GetC_UOM_ID()); splitLine.SetDescription(oldLine.GetDescription()); splitLine.SetIsDescription(oldLine.IsDescription()); splitLine.SetLine(oldLine.GetLine()); splitLine.SetM_AttributeSetInstance_ID(oldLine.GetM_AttributeSetInstance_ID()); //new 13 jan vikas ,assigne by surya sir if (_count > 0) { if (confirmLine.GetM_Locator_ID() > 0) { splitLine.SetM_Locator_ID(confirmLine.GetM_Locator_ID()); } else { splitLine.SetM_Locator_ID(oldLine.GetM_Locator_ID()); } } else { splitLine.SetM_Locator_ID(oldLine.GetM_Locator_ID()); } //End // splitLine.SetM_Locator_ID(oldLine.GetM_Locator_ID()); splitLine.SetM_Product_ID(oldLine.GetM_Product_ID()); splitLine.SetM_Warehouse_ID(oldLine.GetM_Warehouse_ID()); splitLine.SetRef_InOutLine_ID(oldLine.GetRef_InOutLine_ID()); splitLine.AddDescription("Split: from " + oldLine.GetMovementQty()); // Qtys splitLine.SetQty(differenceQty); // Entered/Movement if (!splitLine.Save(Get_TrxName())) { throw new Exception("Cannot save Split Line"); } // Old oldLine.AddDescription("Splitted: from " + oldLine.GetMovementQty()); oldLine.SetQty(Decimal.Subtract(oldLine.GetMovementQty(), differenceQty)); if (!oldLine.Save(Get_TrxName())) { throw new Exception("Cannot save Splited Line"); } // Update Confirmation Line confirmLine.SetTargetQty(Decimal.Subtract(confirmLine.GetTargetQty(), differenceQty)); confirmLine.SetDifferenceQty(Env.ZERO); if (!confirmLine.Save(Get_TrxName())) { throw new Exception("Cannot save Split Confirmation"); } } // for all confirmations _processMsg = "Split @M_InOut_ID@=" + split.GetDocumentNo() + " - @M_InOutConfirm_ID@="; // Create Dispute Confirmation split.ProcessIt(DocActionVariables.ACTION_PREPARE); // split.createConfirmation(); split.Save(Get_TrxName()); MInOutConfirm[] splitConfirms = split.GetConfirmations(true); if (splitConfirms.Length > 0) { int index = 0; if (splitConfirms[index].IsProcessed()) { if (splitConfirms.Length > 1) { index++; // try just next } if (splitConfirms[index].IsProcessed()) { _processMsg += splitConfirms[index].GetDocumentNo() + " processed??"; return; } } splitConfirms[index].SetIsInDispute(true); splitConfirms[index].Save(Get_TrxName()); _processMsg += splitConfirms[index].GetDocumentNo(); // Set Lines to unconfirmed MInOutLineConfirm[] splitConfirmLines = splitConfirms[index].GetLines(false); for (int i = 0; i < splitConfirmLines.Length; i++) { MInOutLineConfirm splitConfirmLine = splitConfirmLines[i]; splitConfirmLine.SetScrappedQty(Env.ZERO); splitConfirmLine.SetConfirmedQty(Env.ZERO); splitConfirmLine.Save(Get_TrxName()); } } else { _processMsg += "??"; } }
/** * Create Invoice Line from Shipment * @param order order * @param ship shipment header * @param sLine shipment line */ private void CreateLine(MOrder order, MInOut ship, MInOutLine sLine) { if (_invoice == null) { _invoice = new MInvoice(order, 0, _DateInvoiced); //---------------------------Column Added by Anuj------------------ int _CountVA009 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA009_' AND IsActive = 'Y'")); if (_CountVA009 > 0) { int _PaymentMethod_ID = order.GetVA009_PaymentMethod_ID(); if (_PaymentMethod_ID > 0) { _invoice.SetVA009_PaymentMethod_ID(_PaymentMethod_ID); } } //-----------------Column Added by Anuj------------------ int _CountVA026 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA026_' AND IsActive = 'Y'")); if (_CountVA026 > 0) { _invoice.SetVA026_LCDetail_ID(order.GetVA026_LCDetail_ID()); } // Added by Bharat on 29 Jan 2018 to set Inco Term from Order if (_invoice.Get_ColumnIndex("C_IncoTerm_ID") > 0) { _invoice.SetC_IncoTerm_ID(order.GetC_IncoTerm_ID()); } if (!_invoice.Save()) { throw new Exception("Could not create Invoice (s)"); } } #region Comment Create Shipment Comment Line // Create Shipment Comment Line //if (_ship == null // || _ship.GetM_InOut_ID() != ship.GetM_InOut_ID()) //{ // MDocType dt = MDocType.Get(GetCtx(), ship.GetC_DocType_ID()); // if (_bp == null || _bp.GetC_BPartner_ID() != ship.GetC_BPartner_ID()) // { // _bp = new MBPartner(GetCtx(), ship.GetC_BPartner_ID(), Get_TrxName()); // } // // Reference: Delivery: 12345 - 12.12.12 // MClient client = MClient.Get(GetCtx(), order.GetAD_Client_ID()); // String AD_Language = client.GetAD_Language(); // if (client.IsMultiLingualDocument() && _bp.GetAD_Language() != null) // { // AD_Language = _bp.GetAD_Language(); // } // if (AD_Language == null) // { // // MessageBox.Show("Set base Language"); // //AD_Language = Language.getBaseAD_Language(); // } // //java.text.SimpleDateFormat format = DisplayType.getDateFormat // // (DisplayType.Date, Language.getLanguage(AD_Language)); // //String reference = dt.GetPrintName(_bp.GetAD_Language()) // // + ": " + ship.GetDocumentNo() // // + " - " + format.format(ship.GetMovementDate()); // String reference = dt.GetPrintName(_bp.GetAD_Language()) // + ": " + ship.GetDocumentNo() // + " - " + ship.GetMovementDate(); // _ship = ship; // // // MInvoiceLine line = new MInvoiceLine(_invoice); // line.SetIsDescription(true); // line.SetDescription(reference); // line.SetLine(_line + sLine.GetLine() - 2); // if (!line.Save()) // { // throw new Exception("Could not create Invoice Comment Line (sh)"); // } // // Optional Ship Address if not Bill Address // if (order.GetBill_Location_ID() != ship.GetC_BPartner_Location_ID()) // { // MLocation addr = MLocation.GetBPLocation(GetCtx(), ship.GetC_BPartner_Location_ID(), null); // line = new MInvoiceLine(_invoice); // line.SetIsDescription(true); // line.SetDescription(addr.ToString()); // line.SetLine(_line + sLine.GetLine() - 1); // if (!line.Save()) // { // throw new Exception("Could not create Invoice Comment Line 2 (sh)"); // } // } //} #endregion // MInvoiceLine line1 = new MInvoiceLine(_invoice); line1.SetShipLine(sLine); line1.SetQtyEntered(sLine.GetQtyEntered()); line1.SetQtyInvoiced(sLine.GetMovementQty()); line1.SetLine(_line + sLine.GetLine()); line1.SetM_AttributeSetInstance_ID(sLine.GetM_AttributeSetInstance_ID()); if (sLine.GetA_Asset_ID() > 0) { line1.SetA_Asset_ID(sLine.GetA_Asset_ID()); if (line1.Get_ColumnIndex("VAFAM_AssetCost") > 0) { int PAcctSchema_ID = 0; int pCurrency_ID = 0; MAcctSchema as1 = MClient.Get(GetCtx(), GetAD_Client_ID()).GetAcctSchema(); if (as1 != null) { PAcctSchema_ID = as1.GetC_AcctSchema_ID(); pCurrency_ID = as1.GetC_Currency_ID(); } decimal LineNetAmt = Decimal.Multiply(line1.GetPriceActual(), line1.GetQtyEntered()); decimal AssetCost = GetAssetCost(sLine.GetA_Asset_ID(), sLine.GetM_Product_ID(), PAcctSchema_ID); AssetCost = Decimal.Multiply(AssetCost, line1.GetQtyEntered()); if (LineNetAmt > 0) { LineNetAmt = MConversionRate.Convert(GetCtx(), LineNetAmt, _invoice.GetC_Currency_ID(), pCurrency_ID, _invoice.GetAD_Client_ID(), _invoice.GetAD_Org_ID()); } decimal Diff = LineNetAmt - AssetCost; line1.Set_Value("VAFAM_AssetCost", AssetCost); line1.Set_Value("VAFAM_Difference", Diff); } } if (!line1.Save()) { throw new Exception("Could not create Invoice Line (s)"); } // Link sLine.SetIsInvoiced(true); if (!sLine.Save()) { throw new Exception("Could not update Shipment Line"); } log.Fine(line1.ToString()); }
/// <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); } }