public LcDetails GetLcDetail(int Invoice_ID, Ctx ctx) { LcDetails lc = new LcDetails(); MInvoice inv = new MInvoice(ctx, Invoice_ID, null); if (inv.GetC_Order_ID() > 0) { MOrder order = new MOrder(ctx, inv.GetC_Order_ID(), null); try { lc.paymethod = order.GetVA009_PaymentMethod_ID(); if (Util.GetValueOfString(DB.ExecuteScalar("SELECT VA009_PaymentBaseType FROM VA009_PaymentMethod WHERE VA009_PaymentMethod_ID=" + order.GetVA009_PaymentMethod_ID(), null, null)) == "L") { lc.lcno = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT MIN(VA026_LCDetail_ID) FROM VA026_LCDetail WHERE IsActive = 'Y' AND DocStatus IN ('CO' , 'CL') AND c_order_id =" + order.GetC_Order_ID(), null, null)); // Check PO Detail tab of Letter of Credit if (lc.lcno == 0) { lc.lcno = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT MIN(lc.VA026_LCDetail_ID) FROM VA026_LCDetail lc INNER JOIN VA026_PODetail sod ON sod.VA026_LCDetail_ID = lc.VA026_LCDetail_ID WHERE sod.IsActive = 'Y' AND lc.IsActive = 'Y' AND lc.DocStatus IN ('CO' , 'CL') AND sod.C_Order_ID =" + order.GetC_Order_ID(), null, null)); if (lc.lcno != 0) { if (Util.GetValueOfString(DB.ExecuteScalar("SELECT VA026_IsLoanRequired FROM VA026_LCDetail WHERE VA026_LCDetail_ID=" + lc.lcno, null, null)) == "Y") { lc.trloan_id = Util.GetValueOfInt(DB.ExecuteScalar("SELECT VA026_TRLoanApplication_ID FROM VA026_TRLoanApplication WHERE IsActive='Y' AND DOCSTATUS='CO' AND VA026_LCDetail_ID= " + lc.lcno, null, null)); } } } else { if (Util.GetValueOfString(DB.ExecuteScalar("SELECT VA026_IsLoanRequired FROM VA026_LCDetail WHERE VA026_LCDetail_ID=" + lc.lcno, null, null)) == "Y") { lc.trloan_id = Util.GetValueOfInt(DB.ExecuteScalar("SELECT VA026_TRLoanApplication_ID FROM VA026_TRLoanApplication WHERE IsActive='Y' AND DOCSTATUS='CO' AND VA026_LCDetail_ID= " + lc.lcno, null, null)); } } } else { lc.lcno = 0; lc.trloan_id = 0; } } catch (Exception e) { } } return(lc); }
/** * Apply Payment Term to Invoice * @param invoice invoice * @return true if payment schedule is valid */ public bool Apply(MInvoice invoice) { if (invoice == null || invoice.Get_ID() == 0) { log.Log(Level.SEVERE, "No valid invoice - " + invoice); return(false); } //Added By Vivek on 17/5/2016 fro Advance Payment GetSchedule(true); if (invoice.GetC_Order_ID() != 0) { return(ApplyNoSchedule(invoice)); } else { return(ApplySchedule(invoice)); } //End Vivek //if (!IsValid()) // return ApplyNoSchedule(invoice); //// //GetSchedule(true); //if (_schedule.Length <= 1) // return ApplyNoSchedule(invoice); //else // only if valid // return ApplySchedule(invoice); }
/// <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()); }
/** * Apply Payment Term with schedule to Invoice * @param invoice invoice * @return true if payment schedule is valid */ private bool ApplySchedule(MInvoice invoice) { DeleteInvoicePaySchedule(invoice.GetC_Invoice_ID(), invoice.Get_TrxName()); // Create Schedule MInvoicePaySchedule ips = null; Decimal remainder = invoice.GetGrandTotal(); for (int i = 0; i < _schedule.Length; i++) { ips = new MInvoicePaySchedule(invoice, _schedule[i]); //int _CountVA009 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA009_' AND IsActive = 'Y'")); //if (_CountVA009 > 0) //{ // ips.SetVA009_ExecutionStatus("A"); // ips.SetC_DocType_ID(invoice.GetC_DocType_ID()); //} int _CountVA009 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA009_' AND IsActive = 'Y'")); if (_CountVA009 > 0) { ips.SetVA009_ExecutionStatus("A"); ips.SetC_DocType_ID(invoice.GetC_DocType_ID()); MOrder _Order = new MOrder(GetCtx(), invoice.GetC_Order_ID(), Get_TrxName()); ips.SetVA009_PaymentMethod_ID(invoice.GetVA009_PaymentMethod_ID()); ips.SetC_PaymentTerm_ID(invoice.GetC_PaymentTerm_ID()); ips.SetVA009_GrandTotal(invoice.GetGrandTotal()); MPaymentTerm payterm = new MPaymentTerm(GetCtx(), invoice.GetC_PaymentTerm_ID(), Get_TrxName()); int _graceDay = payterm.GetGraceDays(); //DateTime? _followUpDay = GetDueDate(invoice); ips.SetVA009_FollowupDate(ips.GetDueDate().Value.AddDays(_graceDay)); //ips.SetVA009_PlannedDueDate(GetDueDate(invoice)); ips.SetVA009_PlannedDueDate(ips.GetDueDate()); //ips.SetDueDate(GetDueDate(invoice)); //change by amit 25-11-2015 StringBuilder _sql = new StringBuilder(); _sql.Clear(); _sql.Append(@"SELECT UNIQUE asch.C_Currency_ID FROM c_acctschema asch INNER JOIN ad_clientinfo ci ON ci.c_acctschema1_id = asch.c_acctschema_id INNER JOIN ad_client c ON c.ad_client_id = ci.ad_client_id INNER JOIN c_invoice i ON c.ad_client_id = i.ad_client_id WHERE i.ad_client_id = " + invoice.GetAD_Client_ID()); int BaseCurrency = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString(), null, null)); if (BaseCurrency != invoice.GetC_Currency_ID()) { _sql.Clear(); _sql.Append(@"SELECT multiplyrate FROM c_conversion_rate WHERE AD_Client_ID = " + invoice.GetAD_Client_ID() + " AND c_currency_id = " + invoice.GetC_Currency_ID() + " AND c_currency_to_id = " + BaseCurrency + " AND " + GlobalVariable.TO_DATE(invoice.GetDateAcct(), true) + " BETWEEN ValidFrom AND ValidTo"); decimal multiplyRate = Util.GetValueOfDecimal(DB.ExecuteScalar(_sql.ToString(), null, null)); if (multiplyRate == 0) { _sql.Clear(); _sql.Append(@"SELECT dividerate FROM c_conversion_rate WHERE AD_Client_ID = " + invoice.GetAD_Client_ID() + " AND c_currency_id = " + BaseCurrency + " AND c_currency_to_id = " + invoice.GetC_Currency_ID() + " AND " + GlobalVariable.TO_DATE(invoice.GetDateAcct(), true) + " BETWEEN ValidFrom AND ValidTo"); multiplyRate = Util.GetValueOfDecimal(DB.ExecuteScalar(_sql.ToString(), null, null)); } ips.SetVA009_OpenAmnt(ips.GetDueAmt() * multiplyRate); } else { ips.SetVA009_OpenAmnt(ips.GetDueAmt()); } ips.SetC_Currency_ID(invoice.GetC_Currency_ID()); ips.SetVA009_BseCurrncy(BaseCurrency); ips.SetVA009_OpnAmntInvce(ips.GetDueAmt()); ips.SetC_BPartner_ID(invoice.GetC_BPartner_ID()); //end string sql = "Select va009_paymentmode, va009_paymenttype, va009_paymenttrigger From va009_paymentmethod where va009_paymentmethod_ID=" + invoice.GetVA009_PaymentMethod_ID() + " AND IsActive = 'Y' AND AD_Client_ID = " + invoice.GetAD_Client_ID(); DataSet ds = new DataSet(); ds = DB.ExecuteDataset(sql); if (ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { for (int j = 0; j < ds.Tables[0].Rows.Count; j++) { ips.SetVA009_PaymentMode(Util.GetValueOfString(ds.Tables[0].Rows[j]["va009_paymentmode"])); ips.SetVA009_PaymentType(Util.GetValueOfString(ds.Tables[0].Rows[j]["va009_paymenttype"])); ips.SetVA009_PaymentTrigger(Util.GetValueOfString(ds.Tables[0].Rows[j]["va009_paymenttrigger"])); ips.SetVA009_ExecutionStatus("A"); } } } ips.Save(invoice.Get_TrxName()); log.Fine(ips.ToString()); remainder = Decimal.Subtract(remainder, ips.GetDueAmt()); } // for all schedules // Remainder - update last if (remainder.CompareTo(Env.ZERO) != 0 && ips != null) { ips.SetDueAmt(Decimal.Add(ips.GetDueAmt(), remainder)); ips.Save(invoice.Get_TrxName()); log.Fine("Remainder=" + remainder + " - " + ips); } // updateInvoice if (invoice.GetC_PaymentTerm_ID() != GetC_PaymentTerm_ID()) { invoice.SetC_PaymentTerm_ID(GetC_PaymentTerm_ID()); } return(invoice.ValidatePaySchedule()); }
/** * Apply Payment Term without schedule to Invoice * @param invoice invoice * @return false as no payment schedule */ private bool ApplyNoSchedule(MInvoice invoice) { DeleteInvoicePaySchedule(invoice.GetC_Invoice_ID(), invoice.Get_TrxName()); // updateInvoice if (invoice.GetC_PaymentTerm_ID() != GetC_PaymentTerm_ID()) { invoice.SetC_PaymentTerm_ID(GetC_PaymentTerm_ID()); } if (invoice.IsPayScheduleValid()) { invoice.SetIsPayScheduleValid(false); } //----------------Anuj------11/09/2015------------------------ int _CountVA009 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA009_' AND IsActive = 'Y'")); if (_CountVA009 > 0) { StringBuilder _sql = new StringBuilder(); MInvoicePaySchedule schedule = new MInvoicePaySchedule(GetCtx(), 0, Get_TrxName()); MPaymentTerm payterm = new MPaymentTerm(GetCtx(), invoice.GetC_PaymentTerm_ID(), Get_TrxName()); schedule.SetAD_Client_ID(invoice.GetAD_Client_ID()); schedule.SetAD_Org_ID(invoice.GetAD_Org_ID()); schedule.SetC_Invoice_ID(invoice.GetC_Invoice_ID()); schedule.SetC_DocType_ID(invoice.GetC_DocType_ID()); schedule.SetC_PaymentTerm_ID(invoice.GetC_PaymentTerm_ID()); schedule.SetVA009_GrandTotal(invoice.GetGrandTotal()); schedule.SetVA009_PaymentMethod_ID(invoice.GetVA009_PaymentMethod_ID()); schedule.SetDueDate(GetDueDate(invoice)); schedule.SetDueAmt(invoice.GetGrandTotal()); schedule.SetDiscountDate(invoice.GetDateInvoiced().Value.AddDays(Util.GetValueOfInt(payterm.GetDiscountDays()))); schedule.SetDiscountAmt((Util.GetValueOfDecimal((invoice.GetGrandTotal() * payterm.GetDiscount()) / 100))); schedule.SetDiscountDays2(invoice.GetDateInvoiced().Value.AddDays(Util.GetValueOfInt(payterm.GetDiscountDays2()))); schedule.SetDiscount2((Util.GetValueOfDecimal((invoice.GetGrandTotal() * payterm.GetDiscount2()) / 100))); schedule.SetVA009_PlannedDueDate(GetDueDate(invoice)); _sql.Clear(); _sql.Append(@"SELECT UNIQUE asch.C_Currency_ID FROM c_acctschema asch INNER JOIN ad_clientinfo ci ON ci.c_acctschema1_id = asch.c_acctschema_id INNER JOIN ad_client c ON c.ad_client_id = ci.ad_client_id INNER JOIN c_invoice i ON c.ad_client_id = i.ad_client_id WHERE i.ad_client_id = " + invoice.GetAD_Client_ID()); int BaseCurrency = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString(), null, null)); if (BaseCurrency != invoice.GetC_Currency_ID()) { // change by amit _sql.Clear(); _sql.Append(@"SELECT multiplyrate FROM c_conversion_rate WHERE AD_Client_ID = " + GetCtx().GetAD_Client_ID() + " AND c_currency_id = " + invoice.GetC_Currency_ID() + " AND c_currency_to_id = " + BaseCurrency + " AND " + GlobalVariable.TO_DATE(invoice.GetDateAcct(), true) + " BETWEEN ValidFrom AND ValidTo"); decimal multiplyRate = Util.GetValueOfDecimal(DB.ExecuteScalar(_sql.ToString(), null, null)); if (multiplyRate == 0) { _sql.Clear(); _sql.Append(@"SELECT dividerate FROM c_conversion_rate WHERE AD_Client_ID = " + GetCtx().GetAD_Client_ID() + " AND c_currency_id = " + BaseCurrency + " AND c_currency_to_id = " + invoice.GetC_Currency_ID() + " AND " + GlobalVariable.TO_DATE(invoice.GetDateAcct(), true) + " BETWEEN ValidFrom AND ValidTo"); multiplyRate = Util.GetValueOfDecimal(DB.ExecuteScalar(_sql.ToString(), null, null)); } schedule.SetVA009_OpenAmnt(invoice.GetGrandTotal() * multiplyRate); } else { schedule.SetVA009_OpenAmnt(invoice.GetGrandTotal()); } schedule.SetC_Currency_ID(invoice.GetC_Currency_ID()); schedule.SetVA009_BseCurrncy(BaseCurrency); schedule.SetVA009_OpnAmntInvce(invoice.GetGrandTotal()); schedule.SetC_BPartner_ID(invoice.GetC_BPartner_ID()); MOrder _Order = new MOrder(GetCtx(), invoice.GetC_Order_ID(), Get_TrxName()); //schedule.SetVA009_PaymentMethod_ID(_Order.GetVA009_PaymentMethod_ID()); //schedule.SetC_PaymentTerm_ID(_Order.GetC_PaymentTerm_ID()); int _graceDay = payterm.GetGraceDays(); DateTime?_followUpDay = GetDueDate(invoice); schedule.SetVA009_FollowupDate(_followUpDay.Value.AddDays(_graceDay)); _sql.Clear(); _sql.Append("Select va009_paymentmode, va009_paymenttype, va009_paymenttrigger From va009_paymentmethod where va009_paymentmethod_ID=" + invoice.GetVA009_PaymentMethod_ID() + " AND IsActive = 'Y' AND AD_Client_ID = " + invoice.GetAD_Client_ID()); DataSet ds = new DataSet(); ds = DB.ExecuteDataset(_sql.ToString()); if (ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { schedule.SetVA009_PaymentMode(Util.GetValueOfString(ds.Tables[0].Rows[i]["va009_paymentmode"])); schedule.SetVA009_PaymentType(Util.GetValueOfString(ds.Tables[0].Rows[i]["va009_paymenttype"])); schedule.SetVA009_PaymentTrigger(Util.GetValueOfString(ds.Tables[0].Rows[i]["va009_paymenttrigger"])); schedule.SetVA009_ExecutionStatus("A"); } } if (!schedule.Save()) { return(false); } return(true); } else { return(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@"); } //*****************************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); if (!ship.Save()) { throw new ArgumentException("@SaveError@ Receipt"); } } else { 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]; 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()); }
/** * Apply Payment Term without schedule to Invoice * @param invoice invoice * @return false as no payment schedule */ #region Advance Payment by Vivek on 16/06/2016 private bool ApplyNoSchedule(MInvoice invoice) { int _CountVA009 = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA009_' AND IsActive = 'Y'")); if (_CountVA009 > 0) { DeleteInvoicePaySchedule(invoice.GetC_Invoice_ID(), invoice.Get_TrxName()); StringBuilder _sql = new StringBuilder(); MInvoicePaySchedule schedule = null; MPaymentTerm payterm = new MPaymentTerm(GetCtx(), invoice.GetC_PaymentTerm_ID(), invoice.Get_TrxName()); Decimal remainder = invoice.GetGrandTotal(); int BaseCurrency = 0; if (Util.GetValueOfInt(DB.ExecuteScalar("Select Count(*) From C_PaySchedule Where C_PaymentTerm_ID=" + invoice.GetC_PaymentTerm_ID())) > 1) { for (int i = 0; i < _schedule.Length; i++) { MPaySchedule _sch = new MPaySchedule(GetCtx(), _schedule[i].GetC_PaySchedule_ID(), Get_TrxName()); #region IsAdvance true on Payment Schedule if (_sch.IsVA009_Advance()) { #region Copy Order Schedules String sql = "SELECT * FROM VA009_OrderPaySchedule WHERE C_Order_ID=" + invoice.GetC_Order_ID() + " AND VA009_IsPaid='Y' ORDER BY Created"; DataSet _ds = new DataSet(); _ds = DB.ExecuteDataset(sql, null); if (_ds.Tables[0].Rows.Count > 0 && _ds.Tables[0].Rows != null) { for (int j = 0; j < _ds.Tables[0].Rows.Count; j++) { schedule = new MInvoicePaySchedule(GetCtx(), 0, invoice.Get_TrxName()); Boolean _isPaid = false; if (Util.GetValueOfString(_ds.Tables[0].Rows[j]["VA009_IsPaid"]) == "Y") { _isPaid = true; } schedule.SetAD_Client_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[j]["AD_Client_ID"])); schedule.SetAD_Org_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[j]["AD_Org_ID"])); schedule.SetC_Invoice_ID(invoice.GetC_Invoice_ID()); schedule.SetC_DocType_ID(invoice.GetC_DocType_ID()); schedule.SetC_PaymentTerm_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[j]["C_PaymentTerm_ID"])); schedule.SetVA009_GrandTotal(Util.GetValueOfInt(_ds.Tables[0].Rows[j]["VA009_GrandTotal"])); schedule.SetVA009_PaymentMethod_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[j]["VA009_PaymentMethod_ID"])); schedule.SetDueDate(invoice.GetDateInvoiced()); schedule.SetDueAmt(Util.GetValueOfInt(_ds.Tables[0].Rows[j]["DueAmt"])); schedule.SetDiscountDate(Util.GetValueOfDateTime(_ds.Tables[0].Rows[j]["DiscountDate"])); schedule.SetDiscountAmt(Util.GetValueOfInt(_ds.Tables[0].Rows[j]["DiscountAmt"])); schedule.SetVA009_IsPaid(_isPaid); schedule.SetC_Payment_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[j]["C_Payment_ID"])); schedule.SetDiscountDays2(Util.GetValueOfDateTime(_ds.Tables[0].Rows[j]["DiscountDays2"])); schedule.SetDiscount2(Util.GetValueOfInt(_ds.Tables[0].Rows[j]["Discount2"])); schedule.SetVA009_PlannedDueDate(Util.GetValueOfDateTime(_ds.Tables[0].Rows[j]["VA009_PlannedDueDate"])); schedule.SetVA009_OpenAmnt(Util.GetValueOfInt(_ds.Tables[0].Rows[j]["VA009_OpenAmnt"])); schedule.SetC_Currency_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[j]["C_Currency_ID"])); schedule.SetVA009_BseCurrncy(Util.GetValueOfInt(_ds.Tables[0].Rows[j]["VA009_bseCurrncy"])); schedule.SetVA009_OpnAmntInvce(Util.GetValueOfInt(_ds.Tables[0].Rows[j]["VA009_OpnAmntInvce"])); schedule.SetC_BPartner_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[j]["C_Bpartner_ID"])); schedule.SetVA009_FollowupDate(Util.GetValueOfDateTime(_ds.Tables[0].Rows[j]["VA009_FollowUpDate"])); schedule.SetVA009_PaymentMode(Util.GetValueOfString(_ds.Tables[0].Rows[j]["va009_paymentmode"])); schedule.SetVA009_PaymentType(Util.GetValueOfString(_ds.Tables[0].Rows[j]["va009_paymenttype"])); schedule.SetVA009_PaymentTrigger(Util.GetValueOfString(_ds.Tables[0].Rows[j]["va009_paymenttrigger"])); schedule.SetVA009_ExecutionStatus(Util.GetValueOfString(_ds.Tables[0].Rows[j]["VA009_ExecutionStatus"])); schedule.SetProcessed(true); if (!schedule.Save(invoice.Get_TrxName())) { return(false); } } } #endregion } #endregion #region IsAdvance false on Payment Schedule else { schedule = new MInvoicePaySchedule(invoice, _schedule[i]); schedule.SetVA009_ExecutionStatus("A"); schedule.SetAD_Client_ID(invoice.GetAD_Client_ID()); schedule.SetAD_Org_ID(invoice.GetAD_Org_ID()); schedule.SetC_Invoice_ID(invoice.GetC_Invoice_ID()); schedule.SetC_DocType_ID(invoice.GetC_DocType_ID()); MOrder _Order = new MOrder(GetCtx(), invoice.GetC_Order_ID(), Get_TrxName()); schedule.SetVA009_PaymentMethod_ID(invoice.GetVA009_PaymentMethod_ID()); schedule.SetC_PaymentTerm_ID(invoice.GetC_PaymentTerm_ID()); schedule.SetVA009_GrandTotal(invoice.GetGrandTotal()); MPaymentTerm paytrm = new MPaymentTerm(GetCtx(), invoice.GetC_PaymentTerm_ID(), Get_TrxName()); int _graceDay = paytrm.GetGraceDays(); //DateTime? _followUpDay = GetDueDate(invoice); schedule.SetVA009_FollowupDate(schedule.GetDueDate().Value.AddDays(_graceDay)); //schedule.SetVA009_PlannedDueDate(GetDueDate(invoice)); schedule.SetVA009_PlannedDueDate(schedule.GetDueDate()); //schedule.SetDueDate(GetDueDate(invoice)); //change by amit 25-11-2015 StringBuilder _sqlBsCrrncy = new StringBuilder(); _sql.Clear(); _sqlBsCrrncy.Append(@"SELECT UNIQUE asch.C_Currency_ID FROM c_acctschema asch INNER JOIN ad_clientinfo ci ON ci.c_acctschema1_id = asch.c_acctschema_id INNER JOIN ad_client c ON c.ad_client_id = ci.ad_client_id INNER JOIN c_invoice i ON c.ad_client_id = i.ad_client_id WHERE i.ad_client_id = " + invoice.GetAD_Client_ID()); BaseCurrency = Util.GetValueOfInt(DB.ExecuteScalar(_sqlBsCrrncy.ToString(), null, null)); if (BaseCurrency != invoice.GetC_Currency_ID()) { _sqlBsCrrncy.Clear(); _sqlBsCrrncy.Append(@"SELECT multiplyrate FROM c_conversion_rate WHERE AD_Client_ID = " + invoice.GetAD_Client_ID() + " AND c_currency_id = " + invoice.GetC_Currency_ID() + " AND c_currency_to_id = " + BaseCurrency + " AND " + GlobalVariable.TO_DATE(invoice.GetDateAcct(), true) + " BETWEEN ValidFrom AND ValidTo"); decimal multiplyRate = Util.GetValueOfDecimal(DB.ExecuteScalar(_sqlBsCrrncy.ToString(), null, null)); if (multiplyRate == 0) { _sqlBsCrrncy.Clear(); _sqlBsCrrncy.Append(@"SELECT dividerate FROM c_conversion_rate WHERE AD_Client_ID = " + invoice.GetAD_Client_ID() + " AND c_currency_id = " + BaseCurrency + " AND c_currency_to_id = " + invoice.GetC_Currency_ID() + " AND " + GlobalVariable.TO_DATE(invoice.GetDateAcct(), true) + " BETWEEN ValidFrom AND ValidTo"); multiplyRate = Util.GetValueOfDecimal(DB.ExecuteScalar(_sqlBsCrrncy.ToString(), null, null)); } schedule.SetVA009_OpenAmnt(schedule.GetDueAmt() * multiplyRate); } else { schedule.SetVA009_OpenAmnt(schedule.GetDueAmt()); } schedule.SetC_Currency_ID(invoice.GetC_Currency_ID()); schedule.SetVA009_BseCurrncy(BaseCurrency); schedule.SetVA009_OpnAmntInvce(schedule.GetDueAmt()); schedule.SetC_BPartner_ID(invoice.GetC_BPartner_ID()); //end string _sqlPaymentMthd = "Select va009_paymentmode, va009_paymenttype, va009_paymenttrigger From va009_paymentmethod where va009_paymentmethod_ID=" + invoice.GetVA009_PaymentMethod_ID() + " AND IsActive = 'Y' AND AD_Client_ID = " + invoice.GetAD_Client_ID(); DataSet dsPayMthd = new DataSet(); dsPayMthd = DB.ExecuteDataset(_sqlPaymentMthd); if (dsPayMthd.Tables != null && dsPayMthd.Tables.Count > 0 && dsPayMthd.Tables[0].Rows.Count > 0) { for (int j = 0; j < dsPayMthd.Tables[0].Rows.Count; j++) { schedule.SetVA009_PaymentMode(Util.GetValueOfString(dsPayMthd.Tables[0].Rows[j]["va009_paymentmode"])); schedule.SetVA009_PaymentType(Util.GetValueOfString(dsPayMthd.Tables[0].Rows[j]["va009_paymenttype"])); schedule.SetVA009_PaymentTrigger(Util.GetValueOfString(dsPayMthd.Tables[0].Rows[j]["va009_paymenttrigger"])); schedule.SetVA009_ExecutionStatus("A"); } } schedule.SetProcessed(true); if (!schedule.Save(invoice.Get_TrxName())) { return(false); } } } #endregion if (invoice.GetC_PaymentTerm_ID() != GetC_PaymentTerm_ID()) { invoice.SetC_PaymentTerm_ID(GetC_PaymentTerm_ID()); } return(invoice.ValidatePaySchedule()); } else if (Util.GetValueOfInt(DB.ExecuteScalar("Select Count(*) From C_PaySchedule Where C_PaymentTerm_ID=" + invoice.GetC_PaymentTerm_ID())) <= 1) { schedule = new MInvoicePaySchedule(GetCtx(), 0, Get_TrxName()); schedule.SetAD_Client_ID(invoice.GetAD_Client_ID()); schedule.SetAD_Org_ID(invoice.GetAD_Org_ID()); schedule.SetC_Invoice_ID(invoice.GetC_Invoice_ID()); schedule.SetC_DocType_ID(invoice.GetC_DocType_ID()); schedule.SetC_PaymentTerm_ID(invoice.GetC_PaymentTerm_ID()); schedule.SetVA009_GrandTotal(invoice.GetGrandTotal()); schedule.SetVA009_PaymentMethod_ID(invoice.GetVA009_PaymentMethod_ID()); schedule.SetDueDate(GetDueDate(invoice)); schedule.SetDueAmt(invoice.GetGrandTotal()); schedule.SetDiscountDate(invoice.GetDateInvoiced().Value.AddDays(Util.GetValueOfInt(payterm.GetDiscountDays()))); schedule.SetDiscountAmt((Util.GetValueOfDecimal((invoice.GetGrandTotal() * payterm.GetDiscount()) / 100))); schedule.SetDiscountDays2(invoice.GetDateInvoiced().Value.AddDays(Util.GetValueOfInt(payterm.GetDiscountDays2()))); schedule.SetDiscount2((Util.GetValueOfDecimal((invoice.GetGrandTotal() * payterm.GetDiscount2()) / 100))); schedule.SetVA009_PlannedDueDate(GetDueDate(invoice)); _sql.Clear(); _sql.Append(@"SELECT UNIQUE asch.C_Currency_ID FROM c_acctschema asch INNER JOIN ad_clientinfo ci ON ci.c_acctschema1_id = asch.c_acctschema_id INNER JOIN ad_client c ON c.ad_client_id = ci.ad_client_id INNER JOIN c_invoice i ON c.ad_client_id = i.ad_client_id WHERE i.ad_client_id = " + invoice.GetAD_Client_ID()); BaseCurrency = Util.GetValueOfInt(DB.ExecuteScalar(_sql.ToString(), null, null)); if (BaseCurrency != invoice.GetC_Currency_ID()) { // change by amit _sql.Clear(); _sql.Append(@"SELECT multiplyrate FROM c_conversion_rate WHERE AD_Client_ID = " + GetCtx().GetAD_Client_ID() + " AND c_currency_id = " + invoice.GetC_Currency_ID() + " AND c_currency_to_id = " + BaseCurrency + " AND " + GlobalVariable.TO_DATE(invoice.GetDateAcct(), true) + " BETWEEN ValidFrom AND ValidTo"); decimal multiplyRate = Util.GetValueOfDecimal(DB.ExecuteScalar(_sql.ToString(), null, null)); if (multiplyRate == 0) { _sql.Clear(); _sql.Append(@"SELECT dividerate FROM c_conversion_rate WHERE AD_Client_ID = " + GetCtx().GetAD_Client_ID() + " AND c_currency_id = " + BaseCurrency + " AND c_currency_to_id = " + invoice.GetC_Currency_ID() + " AND " + GlobalVariable.TO_DATE(invoice.GetDateAcct(), true) + " BETWEEN ValidFrom AND ValidTo"); multiplyRate = Util.GetValueOfDecimal(DB.ExecuteScalar(_sql.ToString(), null, null)); } schedule.SetVA009_OpenAmnt(invoice.GetGrandTotal() * multiplyRate); } else { schedule.SetVA009_OpenAmnt(invoice.GetGrandTotal()); } schedule.SetC_Currency_ID(invoice.GetC_Currency_ID()); schedule.SetVA009_BseCurrncy(BaseCurrency); schedule.SetVA009_OpnAmntInvce(invoice.GetGrandTotal()); schedule.SetC_BPartner_ID(invoice.GetC_BPartner_ID()); MOrder _Order = new MOrder(GetCtx(), invoice.GetC_Order_ID(), Get_TrxName()); //schedule.SetVA009_PaymentMethod_ID(_Order.GetVA009_PaymentMethod_ID()); //schedule.SetC_PaymentTerm_ID(_Order.GetC_PaymentTerm_ID()); int _graceDay = payterm.GetGraceDays(); DateTime?_followUpDay = GetDueDate(invoice); schedule.SetVA009_FollowupDate(_followUpDay.Value.AddDays(_graceDay)); _sql.Clear(); _sql.Append("Select va009_paymentmode, va009_paymenttype, va009_paymenttrigger From va009_paymentmethod where va009_paymentmethod_ID=" + invoice.GetVA009_PaymentMethod_ID() + " AND IsActive = 'Y' AND AD_Client_ID = " + invoice.GetAD_Client_ID()); DataSet ds = new DataSet(); ds = DB.ExecuteDataset(_sql.ToString()); if (ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { schedule.SetVA009_PaymentMode(Util.GetValueOfString(ds.Tables[0].Rows[i]["va009_paymentmode"])); schedule.SetVA009_PaymentType(Util.GetValueOfString(ds.Tables[0].Rows[i]["va009_paymenttype"])); schedule.SetVA009_PaymentTrigger(Util.GetValueOfString(ds.Tables[0].Rows[i]["va009_paymenttrigger"])); schedule.SetVA009_ExecutionStatus("A"); } } if (!schedule.Save()) { return(false); } if (invoice.GetC_PaymentTerm_ID() != GetC_PaymentTerm_ID()) { invoice.SetC_PaymentTerm_ID(GetC_PaymentTerm_ID()); } return(invoice.ValidatePaySchedule()); } } return(true); }