/** * Parent Constructor * @param parent parent * @param M_AttributeSetInstance_ID asi * @param MovementQty qty */ public MInOutLineMA(MInOutLine parent, int M_AttributeSetInstance_ID, Decimal MovementQty) : this(parent.GetCtx(), 0, parent.Get_TrxName()) { SetClientOrg(parent); SetM_InOutLine_ID(parent.GetM_InOutLine_ID()); // SetM_AttributeSetInstance_ID(M_AttributeSetInstance_ID); SetMovementQty(MovementQty); }
/// <summary> /// Shipment Line Constructor /// </summary> /// <param name="sLine">shipment line</param> /// <param name="dateTrx">optional date</param> /// <param name="qty">matched quantity</param> public MMatchPO(MInOutLine sLine, DateTime?dateTrx, Decimal qty) : this(sLine.GetCtx(), 0, sLine.Get_Trx()) { SetClientOrg(sLine); SetM_InOutLine_ID(sLine.GetM_InOutLine_ID()); SetC_OrderLine_ID(sLine.GetC_OrderLine_ID()); if (dateTrx != null) { SetDateTrx(dateTrx); } SetM_Product_ID(sLine.GetM_Product_ID()); SetM_AttributeSetInstance_ID(sLine.GetM_AttributeSetInstance_ID()); SetQty(qty); SetProcessed(true); // auto }
/// <summary> /// Set Shipment Line /// </summary> /// <param name="line">shipment line</param> public void SetInOutLine(MInOutLine line) { SetM_InOutLine_ID(line.GetM_InOutLine_ID()); SetTargetQty(line.GetMovementQty()); // Confirmations in Storage UOM SetConfirmedQty(GetTargetQty()); // suggestion // Enhaced by Siddaraju 2-12-2016 only for gulf oil if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(*) FROM AD_ModuleInfo WHERE IsActive = 'Y' AND Prefix LIKE 'GOM01_'", null, null)) > 0) { _M_Product_ID = line.GetM_Product_ID(); if (_M_Product_ID > 0) { MProduct Prod1 = new MProduct(GetCtx(), _M_Product_ID, Get_TrxName()); SetGOM01_ItemName(Prod1.GetName()); SetGOM01_ItemDescription(Prod1.GetDescription()); SetGOM01_ItemCode(Prod1.GetValue()); } } //end _line = line; }
/// <summary> /// Create Invoice. /// </summary> /// <returns>document no</returns> protected override String DoIt() { StringBuilder invDocumentNo = new StringBuilder(); int count = Util.GetValueOfInt(DB.ExecuteScalar(" SELECT Count(*) FROM M_Inout WHERE ISSOTRX='Y' AND M_Inout_ID=" + GetRecord_ID())); MInOut ship = null; bool isAllownonItem = Util.GetValueOfString(GetCtx().GetContext("$AllowNonItem")).Equals("Y"); if (count > 0) { if (_M_InOut_ID == 0) { throw new ArgumentException("No Shipment"); } // ship = new MInOut(GetCtx(), _M_InOut_ID, Get_Trx()); if (ship.Get_ID() == 0) { throw new ArgumentException("Shipment not found"); } if (!MInOut.DOCSTATUS_Completed.Equals(ship.GetDocStatus())) { // JID_0750: done by Bharat on 05 Feb 2019 if Customer Return document and status is not complete it should give message "Customer Return Not Completed". if (ship.IsReturnTrx()) { throw new ArgumentException("Customer Return Not Completed"); } else { throw new ArgumentException("Shipment Not Completed"); } } } else { if (_M_InOut_ID == 0) { throw new ArgumentException("No Material Receipt"); } // ship = new MInOut(GetCtx(), _M_InOut_ID, Get_Trx()); if (ship.Get_ID() == 0) { throw new ArgumentException("Material Receipt not found"); } if (!MInOut.DOCSTATUS_Completed.Equals(ship.GetDocStatus())) { // JID_0750: done by Bharat on 05 Feb 2019 if Return to vendor document and status is not complete it should give message "Return To Vendor Not Completed". if (ship.IsReturnTrx()) { throw new ArgumentException("Return To Vendor Not Completed"); } else { throw new ArgumentException("Material Receipt Not Completed"); } } } // When record contain more than single order and order having different Payment term or Price List then not to generate invoices // JID_0976 - For conversion Type if (ship.GetC_Order_ID() > 0 && Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT COUNT(DISTINCT c_order.m_pricelist_id) + count(distinct c_order.c_paymentterm_id) + count(distinct COALESCE( c_order.C_ConversionType_ID , " + MConversionType.GetDefault(GetAD_Client_ID()) + @")) as recordcount FROM m_inoutline INNER JOIN c_orderline ON m_inoutline.c_orderline_id = c_orderline.c_orderline_id INNER JOIN c_order ON c_order.c_order_id = c_orderline.c_order_id WHERE m_inoutline.m_inout_id = " + _M_InOut_ID + @" GROUP BY m_inoutline.m_inout_id ", null, Get_Trx())) > 3) { if (ship.IsSOTrx()) { //Different Payment Terms, Price list found against the selected orders, use "Generate Invoice" process to create multiple invoices. throw new ArgumentException(Msg.GetMsg(GetCtx(), "VIS_SoDifferentPayAndPrice")); } else { //Different Payment Terms, Price list found against the selected orders throw new ArgumentException(Msg.GetMsg(GetCtx(), "VIS_DifferentPayAndPrice")); } } // Create Invoice Header MInvoice invoice = new MInvoice(ship, null); //Payment Management int _CountVA009 = Env.IsModuleInstalled("VA009_") ? 1 : 0; // Amortization int _CountVA038 = Env.IsModuleInstalled("VA038_") ? 1 : 0; if (_CountVA009 > 0) { int _PaymentMethod_ID = Util.GetValueOfInt(DB.ExecuteScalar("Select VA009_PaymentMethod_ID From C_Order Where C_Order_ID=" + ship.GetC_Order_ID(), null, Get_Trx())); // 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 int bpPamentMethod_ID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT " + (ship.IsSOTrx() ? " VA009_PaymentMethod_ID " : " VA009_PO_PaymentMethod_ID ") + @" FROM C_BPartner WHERE C_BPartner_ID = " + ship.GetC_BPartner_ID(), null, Get_Trx())); if (bpPamentMethod_ID != 0) { _PaymentMethod_ID = bpPamentMethod_ID; } if (_PaymentMethod_ID > 0) { invoice.SetVA009_PaymentMethod_ID(_PaymentMethod_ID); } } // Letter Of Credit int _CountVA026 = Env.IsModuleInstalled("VA026_") ? 1 : 0; if (_CountVA026 > 0) { int VA026_LCDetail_ID = Util.GetValueOfInt(DB.ExecuteScalar("Select VA026_LCDetail_ID From C_Order Where C_Order_ID=" + ship.GetC_Order_ID(), null, Get_Trx())); if (VA026_LCDetail_ID > 0) { invoice.SetVA026_LCDetail_ID(VA026_LCDetail_ID); } } //end if (ship.IsReturnTrx()) { if (!ship.IsSOTrx()) { // Purchase Return // set target document from documnet type window -- based on documnet type available on material receipt / return to vendor // JID_0779: Create AP Credit memo if we run the Generate TO process from Returm to Vendor window. //if (invoice.GetC_DocTypeTarget_ID() == 0) //{ if (_C_DocType_ID > 0) { invoice.SetC_DocTypeTarget_ID(_C_DocType_ID); } else { int C_DocTypeTarget_ID = DB.GetSQLValue(null, "SELECT C_DocTypeInvoice_ID FROM C_DocType WHERE C_DocType_ID=@param1", ship.GetC_DocType_ID()); if (C_DocTypeTarget_ID > 0) { invoice.SetC_DocTypeTarget_ID(C_DocTypeTarget_ID); } else { invoice.SetC_DocTypeTarget_ID(ship.IsSOTrx() ? MDocBaseType.DOCBASETYPE_ARCREDITMEMO : MDocBaseType.DOCBASETYPE_APCREDITMEMO); } } invoice.SetIsReturnTrx(ship.IsReturnTrx()); invoice.SetIsSOTrx(ship.IsSOTrx()); } else { // Sales Return if (_C_DocType_ID > 0) { invoice.SetC_DocTypeTarget_ID(_C_DocType_ID); } else { if (ship.GetC_Order_ID() >= 0) { int C_DocType_ID = Util.GetValueOfInt(DB.ExecuteScalar("Select C_DocType_ID From C_Order Where C_Order_ID=" + ship.GetC_Order_ID(), null, Get_Trx())); MDocType dt = MDocType.Get(GetCtx(), C_DocType_ID); if (dt.GetC_DocTypeInvoice_ID() != 0) { invoice.SetC_DocTypeTarget_ID(dt.GetC_DocTypeInvoice_ID(), true); } else { invoice.SetC_DocTypeTarget_ID(ship.IsSOTrx() ? MDocBaseType.DOCBASETYPE_ARCREDITMEMO : MDocBaseType.DOCBASETYPE_APCREDITMEMO); } } else { invoice.SetC_DocTypeTarget_ID(ship.IsSOTrx() ? MDocBaseType.DOCBASETYPE_ARCREDITMEMO : MDocBaseType.DOCBASETYPE_APCREDITMEMO); } } } } if (_M_PriceList_ID != 0) { invoice.SetM_PriceList_ID(_M_PriceList_ID); } //Set InvoiceDocumentNo to InvoiceReference if (_InvoiceDocumentNo != null && _InvoiceDocumentNo.Length > 0) { invoice.Set_Value("InvoiceReference", _InvoiceDocumentNo); } //Set TargetDoctype if (_C_DocType_ID > 0 && !ship.IsReturnTrx()) { invoice.Set_Value("C_DocTypeTarget_ID", _C_DocType_ID); } // Added by Bharat on 30 Jan 2018 to set Inco Term from Order if (invoice.Get_ColumnIndex("C_IncoTerm_ID") > 0) { invoice.SetC_IncoTerm_ID(ship.GetC_IncoTerm_ID()); } //To get Payment Rule and set the Payment method if (invoice.GetPaymentRule() != "") { invoice.SetPaymentMethod(invoice.GetPaymentRule()); } if (!invoice.Save()) { //SI_0708 - message was not upto the mark ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Cannot save Invoice. " + pp.GetName()); } throw new ArgumentException("Cannot save Invoice"); } MInOutLine[] shipLines = ship.GetLines(false); DateTime? AmortStartDate = null; DateTime? AmortEndDate = null; count = 0; DataSet ds = null; DataSet dsDoc = null; for (int i = 0; i < shipLines.Length; i++) { MInOutLine sLine = shipLines[i]; // Changes done by Bharat on 06 July 2017 restrict to create invoice if Invoice already created against that for same quantity string sql = @"SELECT ml.QtyEntered - SUM(COALESCE(li.QtyEntered,0)) as QtyEntered, ml.MovementQty- SUM(COALESCE(li.QtyInvoiced, 0)) as QtyInvoiced" + " FROM M_InOutLine ml INNER JOIN C_InvoiceLine li ON li.M_InOutLine_ID = ml.M_InOutLine_ID INNER JOIN C_Invoice ci ON ci.C_Invoice_ID = li.C_Invoice_ID " + " WHERE ci.DocStatus NOT IN ('VO', 'RE') AND ml.M_InOutLine_ID =" + sLine.GetM_InOutLine_ID() + " GROUP BY ml.MovementQty, ml.QtyEntered"; ds = DB.ExecuteDataset(sql, null, Get_Trx()); if (ds != null && ds.Tables[0].Rows.Count > 0) { decimal qtyEntered = Util.GetValueOfDecimal(ds.Tables[0].Rows[0]["QtyEntered"]); decimal qtyInvoiced = Util.GetValueOfDecimal(ds.Tables[0].Rows[0]["QtyInvoiced"]); if (qtyEntered <= 0) { // Getting document number Count if Invoice already generated for Material Receipt string StrSql = "SELECT ci.DocumentNo,li.M_InOutLine_ID FROM C_InvoiceLine li INNER JOIN C_Invoice ci ON ci.C_Invoice_ID = li.C_Invoice_ID " + " WHERE ci.DocStatus NOT IN ('VO', 'RE') AND li.M_InOutLine_ID = " + sLine.GetM_InOutLine_ID(); dsDoc = DB.ExecuteDataset(StrSql, null, Get_Trx()); if (dsDoc != null && dsDoc.Tables[0].Rows.Count > 0) { for (int j = 0; j < dsDoc.Tables[0].Rows.Count; j++) { // JID_1358: Need to show document number in message if Invoice already generated for Material Receipt string no = invDocumentNo.ToString(); if (invDocumentNo.Length > 0 && no != Util.GetValueOfString(dsDoc.Tables[0].Rows[j]["DocumentNo"])) { invDocumentNo.Append(", " + Util.GetValueOfString(dsDoc.Tables[0].Rows[j]["DocumentNo"])); } else { invDocumentNo.Clear(); invDocumentNo.Append(Util.GetValueOfString(dsDoc.Tables[0].Rows[j]["DocumentNo"])); } ds.Dispose(); log.Info("Invoice Line already exist for Receipt Line ID - " + sLine.GetM_InOutLine_ID()); continue; } dsDoc.Dispose(); } } else { MInvoiceLine line = new MInvoiceLine(invoice); line.SetShipLine(sLine); line.SetQtyEntered(qtyEntered); line.SetQtyInvoiced(qtyInvoiced); // Change By Mohit Amortization process ------------- if (_CountVA038 > 0) { if (line.GetM_Product_ID() > 0) { //MProduct pro = new MProduct(GetCtx(), sLine.GetM_Product_ID(), Get_TrxName()); int VA038_AmortizationTemplate_ID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT VA038_AmortizationTemplate_ID FROM M_Product WHERE M_Product_ID = " + sLine.GetM_Product_ID(), null, Get_Trx())); if (VA038_AmortizationTemplate_ID > 0) { line.Set_Value("VA038_AmortizationTemplate_ID", VA038_AmortizationTemplate_ID); DataSet amrtDS = DB.ExecuteDataset("SELECT VA038_AmortizationType,VA038_AmortizationPeriod,VA038_TermSource,VA038_PeriodType,Name FROM VA038_AmortizationTemplate WHERE IsActive='Y' AND VA038_AMORTIZATIONTEMPLATE_ID=" + VA038_AmortizationTemplate_ID); AmortStartDate = null; AmortEndDate = null; if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "A") { AmortStartDate = invoice.GetDateAcct(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "T") { AmortStartDate = invoice.GetDateInvoiced(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "M") { AmortEndDate = AmortStartDate.Value.AddMonths(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "Y") { AmortEndDate = AmortStartDate.Value.AddYears(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } line.Set_Value("FROMDATE", AmortStartDate); line.Set_Value("EndDate", AmortEndDate); if (amrtDS != null) { amrtDS.Dispose(); } } } if (line.GetC_Charge_ID() > 0) { //MCharge charge = new MCharge(GetCtx(), sLine.GetC_Charge_ID(), Get_TrxName()); int VA038_AmortizationTemplate_ID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT VA038_AmortizationTemplate_ID FROM C_Charge WHERE C_Charge_ID = " + sLine.GetC_Charge_ID(), null, Get_Trx())); if (VA038_AmortizationTemplate_ID > 0) { line.Set_Value("VA038_AmortizationTemplate_ID", VA038_AmortizationTemplate_ID); DataSet amrtDS = DB.ExecuteDataset("SELECT VA038_AmortizationType,VA038_AmortizationPeriod,VA038_TermSource,VA038_PeriodType,Name FROM VA038_AmortizationTemplate WHERE IsActive='Y' AND VA038_AMORTIZATIONTEMPLATE_ID=" + VA038_AmortizationTemplate_ID); AmortStartDate = null; AmortEndDate = null; if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "A") { AmortStartDate = invoice.GetDateAcct(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "T") { AmortStartDate = invoice.GetDateInvoiced(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "M") { AmortEndDate = AmortStartDate.Value.AddMonths(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "Y") { AmortEndDate = AmortStartDate.Value.AddYears(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } line.Set_Value("FROMDATE", AmortStartDate); line.Set_Value("EndDate", AmortEndDate); if (amrtDS != null) { amrtDS.Dispose(); } } } } // End Change Amortization process-------------- if (!line.Save()) { //SI_0708 - message was not upto the mark ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Cannot save Invoice Line. " + pp.GetName()); } throw new ArgumentException("Cannot save Invoice Line"); } count++; } ds.Dispose(); } else { MInvoiceLine line = new MInvoiceLine(invoice); // JID_1850 Avoid the duplicate charge line if (sLine.GetC_Charge_ID() > 0 && (!isAllownonItem || _GenerateCharges)) { continue; } line.SetShipLine(sLine); line.SetQtyEntered(sLine.GetQtyEntered()); line.SetQtyInvoiced(sLine.GetMovementQty()); line.Set_ValueNoCheck("IsDropShip", sLine.Get_Value("IsDropShip")); //Arpit Rai 20-Sept-2017 // Change By Mohit Amortization process ------------- if (_CountVA038 > 0) { if (line.GetM_Product_ID() > 0) { //MProduct pro = new MProduct(GetCtx(), sLine.GetM_Product_ID(), Get_TrxName()); int VA038_AmortizationTemplate_ID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT VA038_AmortizationTemplate_ID FROM M_Product WHERE M_Product_ID = " + sLine.GetM_Product_ID(), null, Get_Trx())); if (VA038_AmortizationTemplate_ID > 0) { line.Set_Value("VA038_AmortizationTemplate_ID", VA038_AmortizationTemplate_ID); DataSet amrtDS = DB.ExecuteDataset("SELECT VA038_AmortizationType,VA038_AmortizationPeriod,VA038_TermSource,VA038_PeriodType,Name FROM VA038_AmortizationTemplate WHERE IsActive='Y' AND VA038_AMORTIZATIONTEMPLATE_ID=" + VA038_AmortizationTemplate_ID); AmortStartDate = null; AmortEndDate = null; if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "A") { AmortStartDate = invoice.GetDateAcct(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "T") { AmortStartDate = invoice.GetDateInvoiced(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "M") { AmortEndDate = AmortStartDate.Value.AddMonths(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "Y") { AmortEndDate = AmortStartDate.Value.AddYears(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } line.Set_Value("FROMDATE", AmortStartDate); line.Set_Value("EndDate", AmortEndDate); if (amrtDS != null) { amrtDS.Dispose(); } } } if (line.GetC_Charge_ID() > 0) { //MCharge charge = new MCharge(GetCtx(), sLine.GetC_Charge_ID(), Get_TrxName()); int VA038_AmortizationTemplate_ID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT VA038_AmortizationTemplate_ID FROM C_Charge WHERE C_Charge_ID = " + sLine.GetC_Charge_ID(), null, Get_Trx())); if (VA038_AmortizationTemplate_ID > 0) { line.Set_Value("VA038_AmortizationTemplate_ID", VA038_AmortizationTemplate_ID); DataSet amrtDS = DB.ExecuteDataset("SELECT VA038_AmortizationType,VA038_AmortizationPeriod,VA038_TermSource,VA038_PeriodType,Name FROM VA038_AmortizationTemplate WHERE IsActive='Y' AND VA038_AMORTIZATIONTEMPLATE_ID=" + VA038_AmortizationTemplate_ID); AmortStartDate = null; AmortEndDate = null; if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "A") { AmortStartDate = invoice.GetDateAcct(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "T") { AmortStartDate = invoice.GetDateInvoiced(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "M") { AmortEndDate = AmortStartDate.Value.AddMonths(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "Y") { AmortEndDate = AmortStartDate.Value.AddYears(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } line.Set_Value("FROMDATE", AmortStartDate); line.Set_Value("EndDate", AmortEndDate); if (amrtDS != null) { amrtDS.Dispose(); } } } } // End Change Amortization process-------------- if (!line.Save()) { //SI_0708 - message was not upto the mark ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Cannot save Invoice Line. " + pp.GetName()); } throw new ArgumentException("Cannot save Invoice Line"); } count++; } } #region [Enhancement for Charges Distribution/Generation by Sukhwinder on 13 December 2017] if (_GenerateCharges && count > 0) { StringBuilder OrderSql = new StringBuilder(); OrderSql.Append(" SELECT CO.C_ORDER_ID, " + " SUM(ML.QTYENTERED) AS MRLINEQTY, " + " SUM(OL.QTYENTERED) AS ORDERQTY " + " FROM M_INOUTLINE ML " + " INNER JOIN C_ORDERLINE OL " + " ON OL.C_ORDERLINE_ID = ML.C_ORDERLINE_ID " + " INNER JOIN C_ORDER CO " + " ON CO.C_ORDER_ID = OL.C_ORDER_ID " + " WHERE ML.M_INOUT_ID = " + _M_InOut_ID + " AND (OL.C_CHARGE_ID IS NULL " + " OR OL.C_CHARGE_ID = 0) " + " GROUP BY CO.C_ORDER_ID "); DataSet OrderDS = DB.ExecuteDataset(OrderSql.ToString(), null, Get_Trx()); if (OrderDS != null && OrderDS.Tables[0].Rows.Count > 0) { StringBuilder ChargesSql = new StringBuilder(); for (int index = 0; index < OrderDS.Tables[0].Rows.Count; index++) { ds = null; ChargesSql.Clear(); ChargesSql.Append(" SELECT C_CHARGE_ID, " + " C_ORDERLINE_ID, " + " C_ORDER_ID, " + " C_CURRENCY_ID, " + " PRICEENTERED, " + " PRICEACTUAL, " + " LINENETAMT, " + " QTYENTERED, " + " C_UOM_ID, " + " C_Tax_ID, " + " IsDropShip " + " FROM C_ORDERLINE " + " WHERE C_ORDER_ID IN " + " ( " + Util.GetValueOfInt(OrderDS.Tables[0].Rows[index]["C_ORDER_ID"]) + " ) " + " AND C_CHARGE_ID IS NOT NULL " + " AND C_CHARGE_ID > 0 "); ds = DB.ExecuteDataset(ChargesSql.ToString(), null, Get_Trx()); if (ds != null && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { MInvoiceLine line = new MInvoiceLine(invoice); line.SetQty(1); line.SetQtyEntered(1); line.SetQtyInvoiced(1); line.SetOrderLine(new MOrderLine(GetCtx(), Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_ORDERLINE_ID"]), Get_Trx())); line.SetC_Charge_ID(Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_CHARGE_ID"])); line.SetC_UOM_ID(Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_UOM_ID"])); line.SetC_Tax_ID(Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_TAX_ID"])); decimal SumOfQty = 0; if (Util.GetValueOfInt(OrderDS.Tables[0].Rows[index]["ORDERQTY"]) == 0) { SumOfQty = 1; } else { SumOfQty = Util.GetValueOfInt(OrderDS.Tables[0].Rows[index]["ORDERQTY"]); } decimal amt = (Util.GetValueOfDecimal(ds.Tables[0].Rows[i]["LINENETAMT"]) / SumOfQty) * Util.GetValueOfInt(OrderDS.Tables[0].Rows[index]["MRLINEQTY"]); line.SetPrice(Decimal.Round(amt, 3)); line.SetPriceActual(Decimal.Round(amt, 3)); line.SetPriceEntered(Decimal.Round(amt, 3)); line.SetLineNetAmt(Decimal.Round(amt, 3)); line.Set_ValueNoCheck("IsDropShip", Util.GetValueOfString(ds.Tables[0].Rows[i]["ISDROPSHIP"])); if (_CountVA038 > 0) { if (line.GetC_Charge_ID() > 0) { MCharge charge = new MCharge(GetCtx(), line.GetC_Charge_ID(), Get_TrxName()); if (Util.GetValueOfInt(charge.Get_Value("VA038_AmortizationTemplate_ID")) > 0) { line.Set_Value("VA038_AmortizationTemplate_ID", Util.GetValueOfInt(charge.Get_Value("VA038_AmortizationTemplate_ID"))); DataSet amrtDS = DB.ExecuteDataset("SELECT VA038_AmortizationType,VA038_AmortizationPeriod,VA038_TermSource,VA038_PeriodType,Name FROM VA038_AmortizationTemplate WHERE IsActive='Y' AND VA038_AMORTIZATIONTEMPLATE_ID=" + Util.GetValueOfInt(charge.Get_Value("VA038_AmortizationTemplate_ID"))); AmortStartDate = null; AmortEndDate = null; if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "A") { AmortStartDate = invoice.GetDateAcct(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "T") { AmortStartDate = invoice.GetDateInvoiced(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "M") { AmortEndDate = AmortStartDate.Value.AddMonths(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "Y") { AmortEndDate = AmortStartDate.Value.AddYears(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } line.Set_Value("FROMDATE", AmortStartDate); line.Set_Value("EndDate", AmortEndDate); if (amrtDS != null) { amrtDS.Dispose(); } } } } if (!line.Save()) { //SI_0708 - message was not upto the mark ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Cannot save Invoice Line. " + pp.GetName()); } throw new ArgumentException("Cannot save Invoice Line"); } } } } } } #endregion if (count > 0) { return(invoice.GetDocumentNo()); } else { //Get_Trx().Rollback(); throw new ArgumentException(Msg.GetMsg(GetCtx(), "InvoiceExist") + ": " + invDocumentNo.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, 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 Facts (the accounting logic) for /// MXI. /// (single line) /// <pre> /// NotInvoicedReceipts DR (Receipt Org) /// InventoryClearing CR /// InvoicePV DR CR (difference) /// Commitment /// Expense CR /// Offset DR /// </pre> /// </summary> /// <param name="as1"></param> /// <returns></returns> public override List <Fact> CreateFacts(MAcctSchema as1) { List <Fact> facts = new List <Fact>(); // Nothing to do if (GetM_Product_ID() == 0 || // no Product Env.Signum(GetQty().Value) == 0 || Env.Signum(_receiptLine.GetMovementQty()) == 0) // Qty = 0 { log.Fine("No Product/Qty - M_Product_ID=" + GetM_Product_ID() + ",Qty=" + GetQty() + ",InOutQty=" + _receiptLine.GetMovementQty()); return(facts); } MMatchInv matchInv = (MMatchInv)GetPO(); // create Fact Header Fact fact = new Fact(this, as1, Fact.POST_Actual); SetC_Currency_ID(as1.GetC_Currency_ID()); /** Needs to be handeled in PO Matching as1 no Receipt info * if (_pc.isService()) * { * log.Fine("Service - skipped"); * return fact; * } **/ // NotInvoicedReceipt DR // From Receipt Decimal multiplier = Math.Abs(Decimal.Round(Decimal.Divide(GetQty().Value, _receiptLine.GetMovementQty()), 12, MidpointRounding.AwayFromZero)); FactLine dr = fact.CreateLine(null, GetAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as1), as1.GetC_Currency_ID(), Env.ONE, null); // updated below if (dr == null) { _error = "No Product Costs"; return(null); } dr.SetQty(GetQty()); // dr.setM_Locator_ID(_receiptLine.getM_Locator_ID()); // MInOut receipt = _receiptLine.getParent(); // dr.setLocationFromBPartner(receipt.getC_BPartner_Location_ID(), true); // from Loc // dr.setLocationFromLocator(_receiptLine.getM_Locator_ID(), false); // to Loc Decimal temp = dr.GetAcctBalance(); // Set AmtAcctCr/Dr from Receipt (sets also Project) if (!dr.UpdateReverseLine(MInOut.Table_ID, // Amt updated _receiptLine.GetM_InOut_ID(), _receiptLine.GetM_InOutLine_ID(), multiplier)) { _error = "Mat.Receipt not posted yet"; return(null); } log.Fine("CR - Amt(" + temp + "->" + dr.GetAcctBalance() + ") - " + dr.ToString()); // InventoryClearing CR // From Invoice MAccount expense = _pc.GetAccount(ProductCost.ACCTTYPE_P_InventoryClearing, as1); if (_pc.IsService()) { expense = _pc.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1); } Decimal LineNetAmt = _invoiceLine.GetLineNetAmt(); multiplier = Math.Abs(Decimal.Round(Decimal.Divide(GetQty().Value, _invoiceLine.GetQtyInvoiced()), 12, MidpointRounding.AwayFromZero)); if (multiplier.CompareTo(Env.ONE) != 0) { LineNetAmt = Decimal.Multiply(LineNetAmt, multiplier); } if (_pc.IsService()) { LineNetAmt = dr.GetAcctBalance(); // book out exact receipt amt } FactLine cr = null; if (as1.IsAccrual()) { cr = fact.CreateLine(null, expense, as1.GetC_Currency_ID(), null, LineNetAmt); // updated below if (cr == null) { log.Fine("Line Net Amt=0 - M_Product_ID=" + GetM_Product_ID() + ",Qty=" + GetQty() + ",InOutQty=" + _receiptLine.GetMovementQty()); facts.Add(fact); return(facts); } cr.SetQty(Decimal.Negate(GetQty().Value)); temp = cr.GetAcctBalance(); // Set AmtAcctCr/Dr from Invoice (sets also Project) if (as1.IsAccrual() && !cr.UpdateReverseLine(MInvoice.Table_ID, // Amt updated _invoiceLine.GetC_Invoice_ID(), _invoiceLine.GetC_InvoiceLine_ID(), multiplier)) { _error = "Invoice not posted yet"; return(null); } log.Fine("DR - Amt(" + temp + "->" + cr.GetAcctBalance() + ") - " + cr.ToString()); } else // Cash Acct { MInvoice invoice = _invoiceLine.GetParent(); if (as1.GetC_Currency_ID() == invoice.GetC_Currency_ID()) { LineNetAmt = MConversionRate.Convert(GetCtx(), LineNetAmt, invoice.GetC_Currency_ID(), as1.GetC_Currency_ID(), invoice.GetDateAcct(), invoice.GetC_ConversionType_ID(), invoice.GetAD_Client_ID(), invoice.GetAD_Org_ID()); } cr = fact.CreateLine(null, expense, as1.GetC_Currency_ID(), null, LineNetAmt); cr.SetQty(Decimal.Negate(Decimal.Multiply(GetQty().Value, multiplier))); } cr.SetC_Activity_ID(_invoiceLine.GetC_Activity_ID()); cr.SetC_Campaign_ID(_invoiceLine.GetC_Campaign_ID()); cr.SetC_Project_ID(_invoiceLine.GetC_Project_ID()); cr.SetC_UOM_ID(_invoiceLine.GetC_UOM_ID()); cr.SetUser1_ID(_invoiceLine.GetUser1_ID()); cr.SetUser2_ID(_invoiceLine.GetUser2_ID()); // Invoice Price Variance difference Decimal ipv = Decimal.Negate(Decimal.Add(cr.GetAcctBalance(), dr.GetAcctBalance())); if (Env.Signum(ipv) != 0) { FactLine pv = fact.CreateLine(null, _pc.GetAccount(ProductCost.ACCTTYPE_P_IPV, as1), as1.GetC_Currency_ID(), ipv); pv.SetC_Activity_ID(_invoiceLine.GetC_Activity_ID()); pv.SetC_Campaign_ID(_invoiceLine.GetC_Campaign_ID()); pv.SetC_Project_ID(_invoiceLine.GetC_Project_ID()); pv.SetC_UOM_ID(_invoiceLine.GetC_UOM_ID()); pv.SetUser1_ID(_invoiceLine.GetUser1_ID()); pv.SetUser2_ID(_invoiceLine.GetUser2_ID()); } log.Fine("IPV=" + ipv + "; Balance=" + fact.GetSourceBalance()); MInOut inOut = _receiptLine.GetParent(); bool isReturnTrx = inOut.IsReturnTrx(); if (!IsPosted()) { // Cost Detail Record - data from Expense/IncClearing (CR) record MCostDetail.CreateInvoice(as1, GetAD_Org_ID(), GetM_Product_ID(), matchInv.GetM_AttributeSetInstance_ID(), _invoiceLine.GetC_InvoiceLine_ID(), 0, // No cost element Decimal.Negate(cr.GetAcctBalance()), isReturnTrx ? Decimal.Negate(Utility.Util.GetValueOfDecimal(GetQty())) : Utility.Util.GetValueOfDecimal(GetQty()), // correcting GetDescription(), GetTrx(), GetRectifyingProcess()); // Update Costing UpdateProductInfo(as1.GetC_AcctSchema_ID(), MAcctSchema.COSTINGMETHOD_StandardCosting.Equals(as1.GetCostingMethod())); } // facts.Add(fact); /** Commitment release ****/ if (as1.IsAccrual() && as1.IsCreateCommitment()) { fact = Doc_Order.GetCommitmentRelease(as1, this, Utility.Util.GetValueOfDecimal(GetQty()), _invoiceLine.GetC_InvoiceLine_ID(), Env.ONE); if (fact == null) { return(null); } facts.Add(fact); } // Commitment return(facts); }
/** * Shipment Constructor * @param shipment shipment * @param shipLine shipment line * @param deliveryCount 0 or number of delivery */ public MAsset(MInOut shipment, MInOutLine shipLine, int deliveryCount) : this(shipment.GetCtx(), 0, shipment.Get_TrxName()) { SetClientOrg(shipment); SetValueNameDescription(shipment, shipLine, deliveryCount); // Header //SetIsOwned(true); SetC_BPartner_ID(shipment.GetC_BPartner_ID()); SetC_BPartner_Location_ID(shipment.GetC_BPartner_Location_ID()); SetAD_User_ID(shipment.GetAD_User_ID()); SetM_Locator_ID(shipLine.GetM_Locator_ID()); SetIsInPosession(true); SetAssetServiceDate(shipment.GetDateAcct()); // Line VAdvantage.Model.MProduct product = shipLine.GetProduct(); SetM_Product_ID(product.GetM_Product_ID()); SetA_Asset_Group_ID(product.GetA_Asset_Group_ID()); //////////////////////////////* //Changes for vafam // SetAssetServiceDate(shipment.GetMovementDate()); //SetGuaranteeDate(TimeUtil.AddDays(shipment.GetMovementDate(), product.GetGuaranteeDays())); MAssetGroup _assetGroup = new MAssetGroup(GetCtx(), GetA_Asset_Group_ID(), shipment.Get_TrxName()); if (_assetGroup.IsOwned()) { SetIsOwned(true); //SetC_BPartner_ID(0); } if (_assetGroup.IsDepreciated()) { SetIsDepreciated(true); SetIsFullyDepreciated(false); } //////////////////////////////////// //Change by Sukhwinder for setting Asset type and amortization template on Asset window, MANTIS ID:1762 int countVA038 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA038_' ")); Set_Value("VAFAM_AssetType", _assetGroup.Get_Value("VAFAM_AssetType").ToString()); if (countVA038 > 0) { Set_Value("VA038_AmortizationTemplate_ID", VAdvantage.Utility.Util.GetValueOfInt(_assetGroup.Get_Value("VA038_AmortizationTemplate_ID"))); } Set_Value("VAFAM_DepreciationType_ID", VAdvantage.Utility.Util.GetValueOfInt(_assetGroup.Get_Value("VAFAM_DepreciationType_ID"))); //////////////////////////////////// // Guarantee & Version SetGuaranteeDate(TimeUtil.AddDays(shipment.GetMovementDate(), product.GetGuaranteeDays())); SetVersionNo(product.GetVersionNo()); if (shipLine.GetM_AttributeSetInstance_ID() != 0) // Instance { MAttributeSetInstance asi = new MAttributeSetInstance(GetCtx(), shipLine.GetM_AttributeSetInstance_ID(), Get_TrxName()); SetM_AttributeSetInstance_ID(asi.GetM_AttributeSetInstance_ID()); SetLot(asi.GetLot()); SetSerNo(asi.GetSerNo()); } SetHelp(shipLine.GetDescription()); // Qty int units = product.GetSupportUnits(); if (units == 0) { units = 1; } if (deliveryCount != 0) // one asset per UOM { SetQty(shipLine.GetMovementQty(), units); } else { SetQty((Decimal)units); } SetM_InOutLine_ID(shipLine.GetM_InOutLine_ID()); // Activate MAssetGroup ag = MAssetGroup.Get(GetCtx(), GetA_Asset_Group_ID()); if (!ag.IsCreateAsActive()) { SetIsActive(false); } }
/// <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()); }
/// <summary> /// Create Invoice. /// </summary> /// <returns>document no</returns> protected override String DoIt() { //log.info("M_InOut_ID=" + _M_InOut_ID // + ", M_PriceList_ID=" + _M_PriceList_ID // + ", InvoiceDocumentNo=" + _InvoiceDocumentNo); // Message Display Wrong Done Vikas and Assigned by Gurinder int count = Util.GetValueOfInt(DB.ExecuteScalar(" SELECT Count(*) FROM M_Inout WHERE ISSOTRX='Y' AND M_Inout_ID=" + GetRecord_ID())); MInOut ship = null; if (count > 0) { if (_M_InOut_ID == 0) { throw new ArgumentException("No Shipment"); } // ship = new MInOut(GetCtx(), _M_InOut_ID, Get_Trx()); if (ship.Get_ID() == 0) { throw new ArgumentException("Shipment not found"); } if (!MInOut.DOCSTATUS_Completed.Equals(ship.GetDocStatus())) { throw new ArgumentException("Shipment not completed"); } } else { if (_M_InOut_ID == 0) { throw new ArgumentException("No Material Receipt"); } // ship = new MInOut(GetCtx(), _M_InOut_ID, Get_Trx()); if (ship.Get_ID() == 0) { throw new ArgumentException("Material Receipt not found"); } if (!MInOut.DOCSTATUS_Completed.Equals(ship.GetDocStatus())) { throw new ArgumentException("Material Receipt not completed"); } } //***********************END*****************************// MInvoice invoice = new MInvoice(ship, null); //-------------Column Added by Anuj---------------------- //int _CountVA009 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA009_' AND IsActive = 'Y'")); int _CountVA009 = Env.IsModuleInstalled("VA009_") ? 1 : 0; // Code by Mohit Amortization process //int _CountVA038 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA038_' AND IsActive = 'Y'")); int _CountVA038 = Env.IsModuleInstalled("VA038_") ? 1 : 0; // End Amortization Code if (_CountVA009 > 0) { int _PaymentMethod_ID = Util.GetValueOfInt(DB.ExecuteScalar("Select VA009_PaymentMethod_ID From C_Order Where C_Order_ID=" + ship.GetC_Order_ID())); if (_PaymentMethod_ID > 0) { invoice.SetVA009_PaymentMethod_ID(_PaymentMethod_ID); } } //-------------Column Added by Anuj---------------------- // added by Amit 26-may-2016 //int _CountVA026 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA026_' AND IsActive = 'Y'")); int _CountVA026 = Env.IsModuleInstalled("VA026_") ? 1 : 0; if (_CountVA026 > 0) { MOrder order = new MOrder(GetCtx(), ship.GetC_Order_ID(), Get_Trx()); if (order != null && order.GetC_Order_ID() > 0) { invoice.SetVA026_LCDetail_ID(order.GetVA026_LCDetail_ID()); } } //end if (ship.IsReturnTrx()) { if (!ship.IsSOTrx()) { // Purchase Return // set target document from documnet type window -- based on documnet type available on material receipt / return to vendor if (invoice.GetC_DocTypeTarget_ID() == 0) { int C_DocTypeTarget_ID = DB.GetSQLValue(null, "SELECT C_DocTypeInvoice_ID FROM C_DocType WHERE C_DocType_ID=@param1", ship.GetC_DocType_ID()); if (C_DocTypeTarget_ID >= 0) { invoice.SetC_DocTypeTarget_ID(C_DocTypeTarget_ID); } else { invoice.SetC_DocTypeTarget_ID(ship.IsSOTrx() ? MDocBaseType.DOCBASETYPE_ARCREDITMEMO : MDocBaseType.DOCBASETYPE_APCREDITMEMO); } } invoice.SetIsReturnTrx(ship.IsReturnTrx()); invoice.SetIsSOTrx(ship.IsSOTrx()); } else { // Sales Return if (ship.GetC_Order_ID() >= 0) { MOrder order = new MOrder(GetCtx(), ship.GetC_Order_ID(), Get_Trx()); MDocType dt = MDocType.Get(GetCtx(), order.GetC_DocType_ID()); if (dt.GetC_DocTypeInvoice_ID() != 0) { invoice.SetC_DocTypeTarget_ID(dt.GetC_DocTypeInvoice_ID(), true); } else { invoice.SetC_DocTypeTarget_ID(ship.IsSOTrx() ? MDocBaseType.DOCBASETYPE_ARCREDITMEMO : MDocBaseType.DOCBASETYPE_APCREDITMEMO); } } else { invoice.SetC_DocTypeTarget_ID(ship.IsSOTrx() ? MDocBaseType.DOCBASETYPE_ARCREDITMEMO : MDocBaseType.DOCBASETYPE_APCREDITMEMO); } } } if (_M_PriceList_ID != 0) { invoice.SetM_PriceList_ID(_M_PriceList_ID); } if (_InvoiceDocumentNo != null && _InvoiceDocumentNo.Length > 0) { invoice.SetDocumentNo(_InvoiceDocumentNo); } // Added by Bharat on 30 Jan 2018 to set Inco Term from Order if (invoice.Get_ColumnIndex("C_IncoTerm_ID") > 0) { invoice.SetC_IncoTerm_ID(ship.GetC_IncoTerm_ID()); } if (!invoice.Save()) { //SI_0708 - message was not upto the mark ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Cannot save Invoice. " + pp.GetName()); } throw new ArgumentException("Cannot save Invoice"); //return GetReterivedError(invoice, "Cannot save Invoice"); } MInOutLine[] shipLines = ship.GetLines(false); DateTime? AmortStartDate = null; DateTime? AmortEndDate = null; count = 0; DataSet ds = null; for (int i = 0; i < shipLines.Length; i++) { MInOutLine sLine = shipLines[i]; // Changes done by Bharat on 06 July 2017 restrict to create invoice if Invoice already created against that for same quantity string sql = @"SELECT ml.QtyEntered - SUM(COALESCE(li.QtyEntered,0)) as QtyEntered, ml.MovementQty-SUM(COALESCE(li.QtyInvoiced,0)) as QtyInvoiced FROM M_InOutLine ml INNER JOIN C_InvoiceLine li ON li.M_InOutLine_ID = ml.M_InOutLine_ID INNER JOIN C_Invoice ci ON ci.C_Invoice_ID = li.C_Invoice_ID WHERE ci.DocStatus NOT IN ('VO', 'RE') AND ml.M_InOutLine_ID =" + sLine.GetM_InOutLine_ID() + " GROUP BY ml.MovementQty, ml.QtyEntered"; ds = DB.ExecuteDataset(sql, null, Get_Trx()); if (ds != null && ds.Tables[0].Rows.Count > 0) { decimal qtyEntered = Util.GetValueOfDecimal(ds.Tables[0].Rows[0][0]); decimal qtyInvoiced = Util.GetValueOfDecimal(ds.Tables[0].Rows[0][1]); if (qtyEntered <= 0) { ds.Dispose(); log.Info("Invoice Line already exist for Receipt Line ID - " + sLine.GetM_InOutLine_ID()); continue; } else { MInvoiceLine line = new MInvoiceLine(invoice); line.SetShipLine(sLine); //line.SetQtyEntered(sLine.GetQtyEntered()); //line.SetQtyInvoiced(sLine.GetMovementQty()); line.SetQtyEntered(qtyEntered); line.SetQtyInvoiced(qtyInvoiced); // Change By Mohit Amortization process ------------- if (_CountVA038 > 0) { if (line.GetM_Product_ID() > 0) { MProduct pro = new MProduct(GetCtx(), sLine.GetM_Product_ID(), Get_TrxName()); if (Util.GetValueOfInt(pro.Get_Value("VA038_AmortizationTemplate_ID")) > 0) { line.Set_Value("VA038_AmortizationTemplate_ID", Util.GetValueOfInt(pro.Get_Value("VA038_AmortizationTemplate_ID"))); DataSet amrtDS = DB.ExecuteDataset("SELECT VA038_AmortizationType,VA038_AmortizationPeriod,VA038_TermSource,VA038_PeriodType,Name FROM VA038_AmortizationTemplate WHERE IsActive='Y' AND VA038_AMORTIZATIONTEMPLATE_ID=" + Util.GetValueOfInt(pro.Get_Value("VA038_AmortizationTemplate_ID"))); AmortStartDate = null; AmortEndDate = null; if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "A") { AmortStartDate = invoice.GetDateAcct(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "T") { AmortStartDate = invoice.GetDateInvoiced(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "M") { AmortEndDate = AmortStartDate.Value.AddMonths(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "Y") { AmortEndDate = AmortStartDate.Value.AddYears(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } line.Set_Value("FROMDATE", AmortStartDate); line.Set_Value("EndDate", AmortEndDate); if (amrtDS != null) { amrtDS.Dispose(); } } } if (line.GetC_Charge_ID() > 0) { MCharge charge = new MCharge(GetCtx(), sLine.GetC_Charge_ID(), Get_TrxName()); if (Util.GetValueOfInt(charge.Get_Value("VA038_AmortizationTemplate_ID")) > 0) { line.Set_Value("VA038_AmortizationTemplate_ID", Util.GetValueOfInt(charge.Get_Value("VA038_AmortizationTemplate_ID"))); DataSet amrtDS = DB.ExecuteDataset("SELECT VA038_AmortizationType,VA038_AmortizationPeriod,VA038_TermSource,VA038_PeriodType,Name FROM VA038_AmortizationTemplate WHERE IsActive='Y' AND VA038_AMORTIZATIONTEMPLATE_ID=" + Util.GetValueOfInt(charge.Get_Value("VA038_AmortizationTemplate_ID"))); AmortStartDate = null; AmortEndDate = null; if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "A") { AmortStartDate = invoice.GetDateAcct(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "T") { AmortStartDate = invoice.GetDateInvoiced(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "M") { AmortEndDate = AmortStartDate.Value.AddMonths(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "Y") { AmortEndDate = AmortStartDate.Value.AddYears(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } line.Set_Value("FROMDATE", AmortStartDate); line.Set_Value("EndDate", AmortEndDate); if (amrtDS != null) { amrtDS.Dispose(); } } } } // End Change Amortization process-------------- if (!line.Save()) { //return GetReterivedError(line, "Cannot save Invoice Line"); //SI_0708 - message was not upto the mark ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Cannot save Invoice Line. " + pp.GetName()); } throw new ArgumentException("Cannot save Invoice Line"); } count++; } ds.Dispose(); } else { MInvoiceLine line = new MInvoiceLine(invoice); line.SetShipLine(sLine); line.SetQtyEntered(sLine.GetQtyEntered()); line.SetQtyInvoiced(sLine.GetMovementQty()); line.Set_ValueNoCheck("IsDropShip", sLine.Get_Value("IsDropShip")); //Arpit Rai 20-Sept-2017 // Change By Mohit Amortization process ------------- if (_CountVA038 > 0) { if (line.GetM_Product_ID() > 0) { MProduct pro = new MProduct(GetCtx(), sLine.GetM_Product_ID(), Get_TrxName()); if (Util.GetValueOfInt(pro.Get_Value("VA038_AmortizationTemplate_ID")) > 0) { line.Set_Value("VA038_AmortizationTemplate_ID", Util.GetValueOfInt(pro.Get_Value("VA038_AmortizationTemplate_ID"))); DataSet amrtDS = DB.ExecuteDataset("SELECT VA038_AmortizationType,VA038_AmortizationPeriod,VA038_TermSource,VA038_PeriodType,Name FROM VA038_AmortizationTemplate WHERE IsActive='Y' AND VA038_AMORTIZATIONTEMPLATE_ID=" + Util.GetValueOfInt(pro.Get_Value("VA038_AmortizationTemplate_ID"))); AmortStartDate = null; AmortEndDate = null; if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "A") { AmortStartDate = invoice.GetDateAcct(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "T") { AmortStartDate = invoice.GetDateInvoiced(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "M") { AmortEndDate = AmortStartDate.Value.AddMonths(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "Y") { AmortEndDate = AmortStartDate.Value.AddYears(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } line.Set_Value("FROMDATE", AmortStartDate); line.Set_Value("EndDate", AmortEndDate); if (amrtDS != null) { amrtDS.Dispose(); } } } if (line.GetC_Charge_ID() > 0) { MCharge charge = new MCharge(GetCtx(), sLine.GetC_Charge_ID(), Get_TrxName()); if (Util.GetValueOfInt(charge.Get_Value("VA038_AmortizationTemplate_ID")) > 0) { line.Set_Value("VA038_AmortizationTemplate_ID", Util.GetValueOfInt(charge.Get_Value("VA038_AmortizationTemplate_ID"))); DataSet amrtDS = DB.ExecuteDataset("SELECT VA038_AmortizationType,VA038_AmortizationPeriod,VA038_TermSource,VA038_PeriodType,Name FROM VA038_AmortizationTemplate WHERE IsActive='Y' AND VA038_AMORTIZATIONTEMPLATE_ID=" + Util.GetValueOfInt(charge.Get_Value("VA038_AmortizationTemplate_ID"))); AmortStartDate = null; AmortEndDate = null; if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "A") { AmortStartDate = invoice.GetDateAcct(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "T") { AmortStartDate = invoice.GetDateInvoiced(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "M") { AmortEndDate = AmortStartDate.Value.AddMonths(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "Y") { AmortEndDate = AmortStartDate.Value.AddYears(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } line.Set_Value("FROMDATE", AmortStartDate); line.Set_Value("EndDate", AmortEndDate); if (amrtDS != null) { amrtDS.Dispose(); } } } } // End Change Amortization process-------------- if (!line.Save()) { //return GetReterivedError(line, "Cannot save Invoice Line"); //SI_0708 - message was not upto the mark ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Cannot save Invoice Line. " + pp.GetName()); } throw new ArgumentException("Cannot save Invoice Line"); } count++; } } #region [Enhancement for Charges Distribution/Generation by Sukhwinder on 13 December 2017] if (_GenerateCharges && count > 0) { StringBuilder OrderSql = new StringBuilder(); OrderSql.Append(" SELECT CO.C_ORDER_ID, " + " SUM(ML.QTYENTERED) AS MRLINEQTY, " + " SUM(OL.QTYENTERED) AS ORDERQTY, " + " SUM(OL.QTYENTERED *OL.PRICEENTERED) AS LINEAMT, " + " SUM(ML.QTYENTERED*OL.PRICEENTERED) AS MRLINEVALUE " + " FROM M_INOUTLINE ML " + " INNER JOIN C_ORDERLINE OL " + " ON OL.C_ORDERLINE_ID = ML.C_ORDERLINE_ID " + " INNER JOIN C_ORDER CO " + " ON CO.C_ORDER_ID = OL.C_ORDER_ID " + " WHERE ML.M_INOUT_ID = " + _M_InOut_ID + " AND (OL.C_CHARGE_ID IS NULL " + " OR OL.C_CHARGE_ID = 0) " + " GROUP BY CO.C_ORDER_ID "); DataSet OrderDS = DB.ExecuteDataset(OrderSql.ToString(), null, Get_Trx()); if (OrderDS != null && OrderDS.Tables[0].Rows.Count > 0) { StringBuilder ChargesSql = new StringBuilder(); for (int index = 0; index < OrderDS.Tables[0].Rows.Count; index++) { ds = null; ChargesSql.Clear(); ChargesSql.Append(" SELECT C_CHARGE_ID, " + " C_ORDERLINE_ID, " + " C_ORDER_ID, " + " C_CURRENCY_ID, " + " PRICEENTERED, " + " PRICEACTUAL, " + " LINENETAMT, " + " QTYENTERED, " + " C_UOM_ID, " + " C_Tax_ID, " + " IsDropShip " + " FROM C_ORDERLINE " + " WHERE C_ORDER_ID IN " + " ( " + Util.GetValueOfInt(OrderDS.Tables[0].Rows[index]["C_ORDER_ID"]) + " ) " + " AND C_CHARGE_ID IS NOT NULL " + " AND C_CHARGE_ID > 0 "); ds = DB.ExecuteDataset(ChargesSql.ToString(), null, Get_Trx()); if (ds != null && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { MInvoiceLine line = new MInvoiceLine(invoice); line.SetQty(1); line.SetQtyEntered(1); line.SetQtyInvoiced(1); line.SetOrderLine(new MOrderLine(GetCtx(), Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_ORDERLINE_ID"]), Get_Trx())); line.SetC_Charge_ID(Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_CHARGE_ID"])); line.SetC_UOM_ID(Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_UOM_ID"])); line.SetC_Tax_ID(Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_TAX_ID"])); decimal SumOfQty = 0; decimal SumOfvalue = 0; decimal sototval = 0; string sql = "SELECT SUM(OL.QTYENTERED *OL.PRICEENTERED) AS LINEAMT from C_ORDER CO,C_ORDERLINE OL WHERE CO.C_ORDER_ID=OL.C_ORDER_ID AND (OL.C_CHARGE_ID IS NULL OR OL.C_CHARGE_ID = 0) and CO.C_ORDER_ID =" + ship.GetC_Order_ID(); sototval = VAdvantage.Utility.Util.GetValueOfDecimal(DB.ExecuteScalar(sql)); if (Util.GetValueOfInt(OrderDS.Tables[0].Rows[index]["ORDERQTY"]) == 0) { SumOfQty = 1; } else { SumOfQty = Util.GetValueOfInt(OrderDS.Tables[0].Rows[index]["ORDERQTY"]); SumOfvalue = Util.GetValueOfDecimal(OrderDS.Tables[0].Rows[index]["LINEAMT"]); } //decimal amt = (Util.GetValueOfDecimal(ds.Tables[0].Rows[i]["LINENETAMT"]) / SumOfQty) * Util.GetValueOfInt(OrderDS.Tables[0].Rows[index]["MRLINEQTY"]); decimal amt = (Util.GetValueOfDecimal(ds.Tables[0].Rows[i]["LINENETAMT"]) / sototval) * Util.GetValueOfInt(OrderDS.Tables[0].Rows[index]["MRLINEVALUE"]); line.SetPrice(Decimal.Round(amt, 3)); line.SetPriceActual(Decimal.Round(amt, 3)); line.SetPriceEntered(Decimal.Round(amt, 3)); line.SetLineNetAmt(Decimal.Round(amt, 3)); line.Set_ValueNoCheck("IsDropShip", Util.GetValueOfString(ds.Tables[0].Rows[i]["ISDROPSHIP"])); if (_CountVA038 > 0) { if (line.GetC_Charge_ID() > 0) { MCharge charge = new MCharge(GetCtx(), line.GetC_Charge_ID(), Get_TrxName()); if (Util.GetValueOfInt(charge.Get_Value("VA038_AmortizationTemplate_ID")) > 0) { line.Set_Value("VA038_AmortizationTemplate_ID", Util.GetValueOfInt(charge.Get_Value("VA038_AmortizationTemplate_ID"))); DataSet amrtDS = DB.ExecuteDataset("SELECT VA038_AmortizationType,VA038_AmortizationPeriod,VA038_TermSource,VA038_PeriodType,Name FROM VA038_AmortizationTemplate WHERE IsActive='Y' AND VA038_AMORTIZATIONTEMPLATE_ID=" + Util.GetValueOfInt(charge.Get_Value("VA038_AmortizationTemplate_ID"))); AmortStartDate = null; AmortEndDate = null; if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "A") { AmortStartDate = invoice.GetDateAcct(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_TermSource"]) == "T") { AmortStartDate = invoice.GetDateInvoiced(); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "M") { AmortEndDate = AmortStartDate.Value.AddMonths(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } if (Util.GetValueOfString(amrtDS.Tables[0].Rows[0]["VA038_PeriodType"]) == "Y") { AmortEndDate = AmortStartDate.Value.AddYears(Util.GetValueOfInt(amrtDS.Tables[0].Rows[0]["VA038_AmortizationPeriod"])); } line.Set_Value("FROMDATE", AmortStartDate); line.Set_Value("EndDate", AmortEndDate); if (amrtDS != null) { amrtDS.Dispose(); } } } } if (!line.Save()) { //return GetReterivedError(line, "Cannot save Invoice Line"); //SI_0708 - message was not upto the mark ValueNamePair pp = VAdvantage.Logging.VLogger.RetrieveError(); if (pp != null) { throw new ArgumentException("Cannot save Invoice Line. " + pp.GetName()); } throw new ArgumentException("Cannot save Invoice Line"); } } } } } } #endregion if (count > 0) { return(invoice.GetDocumentNo()); } else { Get_Trx().Rollback(); return(Msg.GetMsg(GetCtx(), "InvoiceExist")); } }
/// <summary> /// Create Facts (the accounting logic) for /// MMS, MMR. /// <pre> /// Shipment /// CoGS (RevOrg) DR /// Inventory CR /// Shipment of Project Issue /// CoGS DR /// Project CR /// Receipt /// Inventory DR /// NotInvoicedReceipt CR /// </pre> /// </summary> /// <param name="as1">accounting schema</param> /// <returns>Fact</returns> public override List <Fact> CreateFacts(MAcctSchema as1) { // create Fact Header Fact fact = new Fact(this, as1, Fact.POST_Actual); SetC_Currency_ID(as1.GetC_Currency_ID()); // Line pointers FactLine dr = null; FactLine cr = null; // *** Sales - Shipment if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_MATERIALDELIVERY)) { for (int i = 0; i < _lines.Length; i++) { DocLine line = _lines[i]; MInOutLine sLine = new MInOutLine(GetCtx(), line.Get_ID(), null); Decimal costs = 0; if (sLine.GetA_Asset_ID() > 0) { costs = Util.GetValueOfDecimal(DB.ExecuteScalar(@"SELECT cost.CUrrentcostPrice FROM m_cost cost INNER JOIN A_Asset ass ON(ass.a_asset_ID=cost.a_asset_ID) INNER JOIN M_InOutLine IOL ON(IOL.A_Asset_ID =ass.A_Asset_ID) WHERE IOL.M_InOutLine_ID=" + sLine.GetM_InOutLine_ID() + @" ORDER By cost.created desc")); // Change if Cost not found against Asset then get Product Cost if (Env.Signum(costs) == 0) // zero costs OK { costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), true); } } else { costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), true); } if (Env.Signum(costs) == 0) // zero costs OK { MProduct product = line.GetProduct(); if (product.IsStocked()) { _error = "No Costs for " + line.GetProduct().GetName(); log.Log(Level.WARNING, _error); return(null); } else // ignore service { continue; } } if (!IsReturnTrx()) { // CoGS DR dr = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Cogs, as1), as1.GetC_Currency_ID(), costs, null); if (dr == null) { _error = "FactLine DR not created: " + line; log.Log(Level.WARNING, _error); return(null); } dr.SetM_Locator_ID(line.GetM_Locator_ID()); dr.SetLocationFromLocator(line.GetM_Locator_ID(), true); // from Loc dr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), false); // to Loc dr.SetAD_Org_ID(line.GetOrder_Org_ID()); // Revenue X-Org dr.SetQty(Decimal.Negate(line.GetQty().Value)); // Inventory CR cr = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1), as1.GetC_Currency_ID(), null, costs); if (cr == null) { _error = "FactLine CR not created: " + line; log.Log(Level.WARNING, _error); return(null); } cr.SetM_Locator_ID(line.GetM_Locator_ID()); cr.SetLocationFromLocator(line.GetM_Locator_ID(), true); // from Loc cr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), false); // to Loc } else // Reverse accounting entries for returns { // CoGS CR cr = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Cogs, as1), as1.GetC_Currency_ID(), null, costs); if (cr == null) { _error = "FactLine CR not created: " + line; log.Log(Level.WARNING, _error); return(null); } cr.SetM_Locator_ID(line.GetM_Locator_ID()); cr.SetLocationFromLocator(line.GetM_Locator_ID(), true); // from Loc cr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), false); // to Loc cr.SetAD_Org_ID(line.GetOrder_Org_ID()); // Revenue X-Org cr.SetQty(Decimal.Negate(line.GetQty().Value)); // Inventory DR dr = fact.CreateLine(line, line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1), as1.GetC_Currency_ID(), costs, null); if (dr == null) { _error = "FactLine DR not created: " + line; log.Log(Level.WARNING, _error); return(null); } dr.SetM_Locator_ID(line.GetM_Locator_ID()); dr.SetLocationFromLocator(line.GetM_Locator_ID(), true); // from Loc dr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), false); // to Loc } // if (line.GetM_Product_ID() != 0) { if (!IsPosted()) { MCostDetail.CreateShipment(as1, line.GetAD_Org_ID(), line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), line.Get_ID(), 0, costs, IsReturnTrx() ? Decimal.Negate(line.GetQty().Value) : line.GetQty().Value, line.GetDescription(), true, GetTrx(), GetRectifyingProcess()); } } } // for all lines if (!IsPosted()) { UpdateProductInfo(as1.GetC_AcctSchema_ID()); // only for SO! } } // Shipment // *** Purchasing - Receipt else if (GetDocumentType().Equals(MDocBaseType.DOCBASETYPE_MATERIALRECEIPT)) { for (int i = 0; i < _lines.Length; i++) { Decimal costs = 0; DocLine line = _lines[i]; MProduct product = line.GetProduct(); /***********************************************************/ //05,Sep,2011 //Special Check to restic Price varience posting in case of //AvarageInvoice Selected on product Category.Then Neglact the AverageInvoice Cost MProductCategoryAcct pca = MProductCategoryAcct.Get(product.GetCtx(), product.GetM_Product_Category_ID(), as1.GetC_AcctSchema_ID(), null); try { if (as1.IsNotPostPOVariance() && line.GetC_OrderLine_ID() > 0) { MOrderLine oLine = new MOrderLine(product.GetCtx(), line.GetC_OrderLine_ID(), null); MOrder order = new MOrder(product.GetCtx(), oLine.GetC_Order_ID(), null); Decimal convertedCost = MConversionRate.Convert(product.GetCtx(), oLine.GetPriceEntered(), order.GetC_Currency_ID(), as1.GetC_Currency_ID(), line.GetDateAcct(), order.GetC_ConversionType_ID(), oLine.GetAD_Client_ID(), line.GetAD_Org_ID()); costs = Decimal.Multiply(convertedCost, oLine.GetQtyEntered()); } else { costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), false); // non-zero costs } } catch (Exception ex) { log.SaveError("AccountSchemaColumnError", ex); costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), false); // non-zero costs } /***********************************************************/ //Decimal costs = costs = line.GetProductCosts(as1, line.GetAD_Org_ID(), false); // non-zero costs if (Env.Signum(costs) == 0) { _error = "Resubmit - No Costs for " + product.GetName(); log.Log(Level.WARNING, _error); return(null); } // Inventory/Asset DR MAccount assets = line.GetAccount(ProductCost.ACCTTYPE_P_Asset, as1); if (product.IsService()) { assets = line.GetAccount(ProductCost.ACCTTYPE_P_Expense, as1); } if (!IsReturnTrx()) { // Inventory/Asset DR dr = fact.CreateLine(line, assets, as1.GetC_Currency_ID(), costs, null); if (dr == null) { _error = "DR not created: " + line; log.Log(Level.WARNING, _error); return(null); } dr.SetM_Locator_ID(line.GetM_Locator_ID()); dr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), true); // from Loc dr.SetLocationFromLocator(line.GetM_Locator_ID(), false); // to Loc // NotInvoicedReceipt CR cr = fact.CreateLine(line, GetAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as1), as1.GetC_Currency_ID(), null, costs); if (cr == null) { _error = "CR not created: " + line; log.Log(Level.WARNING, _error); return(null); } cr.SetM_Locator_ID(line.GetM_Locator_ID()); cr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), true); // from Loc cr.SetLocationFromLocator(line.GetM_Locator_ID(), false); // to Loc cr.SetQty(Decimal.Negate(line.GetQty().Value)); } else // reverse accounting entries for returns { // Inventory/Asset CR cr = fact.CreateLine(line, assets, as1.GetC_Currency_ID(), null, costs); if (cr == null) { _error = "CR not created: " + line; log.Log(Level.WARNING, _error); return(null); } cr.SetM_Locator_ID(line.GetM_Locator_ID()); cr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), true); // from Loc cr.SetLocationFromLocator(line.GetM_Locator_ID(), false); // to Loc // NotInvoicedReceipt DR dr = fact.CreateLine(line, GetAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as1), as1.GetC_Currency_ID(), costs, null); if (dr == null) { _error = "DR not created: " + line; log.Log(Level.WARNING, _error); return(null); } dr.SetM_Locator_ID(line.GetM_Locator_ID()); dr.SetLocationFromBPartner(GetC_BPartner_Location_ID(), true); // from Loc dr.SetLocationFromLocator(line.GetM_Locator_ID(), false); // to Loc dr.SetQty(Decimal.Negate(line.GetQty().Value)); } } } // Receipt else { _error = "DocumentType unknown: " + GetDocumentType(); log.Log(Level.SEVERE, _error); return(null); } // List <Fact> facts = new List <Fact>(); facts.Add(fact); return(facts); }
/** * Find/Create PO(Inv) Match * @param iLine invoice line * @param sLine receipt line * @param dateTrx date * @param qty qty * @return Match Record */ public static MMatchPO Create(MInvoiceLine iLine, MInOutLine sLine, DateTime?dateTrx, Decimal qty) { Trx trxName = null; Ctx ctx = null; int C_OrderLine_ID = 0; if (iLine != null) { trxName = iLine.Get_Trx(); ctx = iLine.GetCtx(); C_OrderLine_ID = iLine.GetC_OrderLine_ID(); } if (sLine != null) { trxName = sLine.Get_Trx(); ctx = sLine.GetCtx(); C_OrderLine_ID = sLine.GetC_OrderLine_ID(); } MMatchPO retValue = null; String sql = "SELECT * FROM M_MatchPO WHERE C_OrderLine_ID=" + C_OrderLine_ID; // ArrayList list = new ArrayList(); DataSet ds = null; try { ds = DB.ExecuteDataset(sql, null, trxName); foreach (DataRow dr in ds.Tables[0].Rows) { MMatchPO mpo = new MMatchPO(ctx, dr, trxName); if (qty.CompareTo(mpo.GetQty()) == 0) { if (iLine != null) { if (mpo.GetC_InvoiceLine_ID() == 0 || mpo.GetC_InvoiceLine_ID() == iLine.GetC_InvoiceLine_ID()) { mpo.SetC_InvoiceLine_ID(iLine); if (iLine.GetM_AttributeSetInstance_ID() != 0) { if (mpo.GetM_AttributeSetInstance_ID() == 0) { mpo.SetM_AttributeSetInstance_ID(iLine.GetM_AttributeSetInstance_ID()); } else if (mpo.GetM_AttributeSetInstance_ID() != iLine.GetM_AttributeSetInstance_ID()) { continue; } } } else { continue; } } if (sLine != null) { if (mpo.GetM_InOutLine_ID() == 0 || mpo.GetM_InOutLine_ID() == sLine.GetM_InOutLine_ID()) { mpo.SetM_InOutLine_ID(sLine.GetM_InOutLine_ID()); if (sLine.GetM_AttributeSetInstance_ID() != 0) { if (mpo.GetM_AttributeSetInstance_ID() == 0) { mpo.SetM_AttributeSetInstance_ID(sLine.GetM_AttributeSetInstance_ID()); } else if (mpo.GetM_AttributeSetInstance_ID() != sLine.GetM_AttributeSetInstance_ID()) { continue; } } } else { continue; } } retValue = mpo; break; } } } catch (Exception e) { s_log.Log(Level.SEVERE, sql, e); } // Create New if (retValue == null) { if (sLine != null) { retValue = new MMatchPO(sLine, dateTrx, qty); if (iLine != null) { retValue.SetC_InvoiceLine_ID(iLine); } } else if (iLine != null) { retValue = new MMatchPO(iLine, dateTrx, qty); } } return(retValue); }