/// <summary> /// Create Cash Journal Line /// </summary> /// <param name="invoice">Invoice</param> /// <param name="C_InvoicePaySchedule_ID">Invoice Payemt Schedule</param> /// <param name="amt">Amount</param> public void CreateCashLine(MInvoice invoice, int C_InvoicePaySchedule_ID, decimal amt) { SetC_Invoice_ID(invoice.GetC_Invoice_ID()); SetC_InvoicePaySchedule_ID(C_InvoicePaySchedule_ID); SetCashType(CASHTYPE_Invoice); SetC_BPartner_ID(invoice.GetC_BPartner_ID()); // JID_0687: System is not updating the Location on cash journal line in cases of POS order and payment method cash SetC_BPartner_Location_ID(invoice.GetC_BPartner_Location_ID()); SetC_Currency_ID(invoice.GetC_Currency_ID()); // Amount MDocType dt = MDocType.Get(GetCtx(), invoice.GetC_DocType_ID()); if (MDocBaseType.DOCBASETYPE_APINVOICE.Equals(dt.GetDocBaseType()) || MDocBaseType.DOCBASETYPE_ARCREDITMEMO.Equals(dt.GetDocBaseType())) { amt = Decimal.Negate(amt); SetVSS_PAYMENTTYPE("P"); } else { SetVSS_PAYMENTTYPE("R"); } SetAmount(amt); // SetDiscountAmt(Env.ZERO); SetWriteOffAmt(Env.ZERO); SetIsGenerated(true); _invoice = invoice; }
/// <summary> /// Set the document number from Completed Document Sequence after completed /// </summary> private void SetCompletedDocumentNo() { MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID()); // if Overwrite Date on Complete checkbox is true. if (dt.IsOverwriteDateOnComplete()) { SetDateDoc(DateTime.Now.Date); // Std Period open? if (!MPeriod.IsOpen(GetCtx(), GetDateDoc(), dt.GetDocBaseType())) { throw new Exception("@PeriodClosed@"); } } // if Overwrite Sequence on Complete checkbox is true. if (dt.IsOverwriteSeqOnComplete()) { // Set Drafted Document No into Temp Document No. if (Get_ColumnIndex("TempDocumentNo") > 0) { SetTempDocumentNo(GetDocumentNo()); } // Get current next from Completed document sequence defined on Document type String value = MSequence.GetDocumentNo(GetC_DocType_ID(), Get_TrxName(), GetCtx(), true, this); if (value != null) { SetDocumentNo(value); } } }
/// <summary> /// After Save /// </summary> /// <param name="newRecord">new</param> /// <param name="success">success</param> /// <returns>success</returns> protected override bool AfterSave(bool newRecord, bool success) { if (newRecord) { // SELECT Value FROM AD_Ref_List WHERE AD_Reference_ID=183 MDocType[] types = MDocType.GetOfClient(GetCtx()); int count = 0; List <String> baseTypes = new List <String>(); for (int i = 0; i < types.Length; i++) { MDocType type = types[i]; String docBaseType = type.GetDocBaseType(); if (baseTypes.Contains(docBaseType)) { continue; } MPeriodControl pc = new MPeriodControl(this, docBaseType); pc.SetAD_Org_ID(GetAD_Org_ID()); if (pc.Save()) { count++; } baseTypes.Add(docBaseType); } log.Fine("PeriodControl #" + count); } return(success); }
public void CreateCashLine(MInvoice invoice, int C_InvoicePaySchedule_ID, decimal amt) { SetC_Invoice_ID(invoice.GetC_Invoice_ID()); SetC_InvoicePaySchedule_ID(C_InvoicePaySchedule_ID); SetCashType(CASHTYPE_Invoice); SetC_BPartner_ID(invoice.GetC_BPartner_ID()); SetC_Currency_ID(invoice.GetC_Currency_ID()); // Amount MDocType dt = MDocType.Get(GetCtx(), invoice.GetC_DocType_ID()); if (MDocBaseType.DOCBASETYPE_APINVOICE.Equals(dt.GetDocBaseType()) || MDocBaseType.DOCBASETYPE_ARCREDITMEMO.Equals(dt.GetDocBaseType())) { amt = Decimal.Negate(amt); SetVSS_PAYMENTTYPE("P"); } else { SetVSS_PAYMENTTYPE("R"); } SetAmount(amt); // SetDiscountAmt(Env.ZERO); SetWriteOffAmt(Env.ZERO); SetIsGenerated(true); _invoice = invoice; }
/// <summary> ///Get Client Document Type with DocBaseType /// </summary> /// <param name="ctx">Ctx</param> /// <param name="DocBaseType">DocBaseType base document type</param> /// <returns>array of doc types</returns> static public MDocType[] GetOfDocBaseType(Ctx ctx, string docBaseType) { List <MDocType> list = new List <MDocType>(); String sql = "SELECT * FROM C_DocType " + "WHERE AD_Client_ID=" + ctx.GetAD_Client_ID() + " AND DocBaseType='" + docBaseType + "' AND IsActive='Y'" + "ORDER BY C_DocType_ID"; DataSet pstmt = null; try { pstmt = DataBase.DB.ExecuteDataset(sql, null, null); for (int i = 0; i < pstmt.Tables[0].Rows.Count; i++) { DataRow rs = pstmt.Tables[0].Rows[i]; list.Add(new MDocType(ctx, rs, null)); } pstmt = null; } catch (Exception e) { s_log.Log(Level.SEVERE, sql, e); } MDocType[] retValue = new MDocType[list.Count]; retValue = list.ToArray(); return(retValue); }
/// <summary> ///Get Document Type (cached) /// </summary> /// <param name="ctx">Ctx</param> /// <param name="C_DocType_ID">id</param> /// <returns>document type</returns> static public MDocType Get(Ctx ctx, int C_DocType_ID) { int key = (int)C_DocType_ID; MDocType retValue = (MDocType)s_cache[key]; if (retValue == null) { retValue = new MDocType(ctx, C_DocType_ID, null); s_cache.Add(key, retValue); } return(retValue); }
/** * Get Counter Doc Type * @return counter doc type or null if not existing */ public MDocType GetCounterDocType() { MDocType dt = null; if (GetCounter_C_DocType_ID() > 0) { dt = MDocType.Get(GetCtx(), GetCounter_C_DocType_ID()); if (dt.Get_ID() == 0) { dt = null; } } return(dt); }
/** * Get Counter document for document type * @param ctx context * @param C_DocType_ID base document * @return counter document C_DocType_ID or 0 or -1 if no counter doc */ public static int GetCounterDocType_ID(Ctx ctx, int C_DocType_ID) { // Direct Relationship MDocTypeCounter dtCounter = GetCounterDocType(ctx, C_DocType_ID); if (dtCounter != null) { if (!dtCounter.IsCreateCounter() || !dtCounter.IsValid()) { return(-1); } return(dtCounter.GetCounter_C_DocType_ID()); } // Indirect Relationship int Counter_C_DocType_ID = 0; MDocType dt = MDocType.Get(ctx, C_DocType_ID); if (!dt.IsCreateCounter()) { return(-1); } String cDocBaseType = "";// = getCounterDocBaseType(dt.getDocBaseType()); if (cDocBaseType == null) { return(0); } MDocType[] counters = MDocType.GetOfDocBaseType(ctx, cDocBaseType); for (int i = 0; i < counters.Length; i++) { MDocType counter = counters[i]; if (counter.IsDefaultCounterDoc()) { Counter_C_DocType_ID = counter.GetC_DocType_ID(); break; } if (counter.IsDefault()) { Counter_C_DocType_ID = counter.GetC_DocType_ID(); } else if (i == 0) { Counter_C_DocType_ID = counter.GetC_DocType_ID(); } } return(Counter_C_DocType_ID); }
/// <summary> /// Set Invoice - no discount /// </summary> /// <param name="invoice">Invoice</param> public void SetInvoice(MInvoice invoice) { Decimal amt = 0; SetC_Invoice_ID(invoice.GetC_Invoice_ID()); SetCashType(CASHTYPE_Invoice); SetC_BPartner_ID(invoice.GetC_BPartner_ID()); // JID_0687: System is not updating the Location on cash journal line in cases of POS order and payment method cash SetC_BPartner_Location_ID(invoice.GetC_BPartner_Location_ID()); SetC_Currency_ID(invoice.GetC_Currency_ID()); // Amount MDocType dt = MDocType.Get(GetCtx(), invoice.GetC_DocType_ID()); if (invoice.GetRef_C_Invoice_ID() > 0) { //amt = Decimal.Negate(Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT SUM(Al.Amount) FROM c_allocationline al INNER JOIN c_allocationhdr alhdr ON alhdr.c_allocationhdr_ID=al.c_allocationhdr_ID " // + " WHERE alhdr.isactive ='Y' AND Alhdr.Docstatus IN ('CO','CL') and al.c_invoice_id=" + invoice.GetRef_C_Invoice_ID()))); // get amount against invoice wheether cash journal is completed or not // Done by Vivek on 01/03/2016 amt = Decimal.Negate(Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT SUM(cl.Amount) FROM C_CashLine cl INNER JOIN C_Cash cs ON cs.C_Cash_ID=CL.C_CASH_ID WHERE cl.C_Invoice_ID=" + invoice.GetRef_C_Invoice_ID() + " AND cs.DocStatus NOT IN ('VO') "))); } else { amt = invoice.GetGrandTotal(); } if (MDocBaseType.DOCBASETYPE_APINVOICE.Equals(dt.GetDocBaseType()) || MDocBaseType.DOCBASETYPE_ARCREDITMEMO.Equals(dt.GetDocBaseType())) { amt = Decimal.Negate(amt); // set payment type according to invoice document type SetVSS_PAYMENTTYPE("P"); } else { // set payment type according to invoice document type SetVSS_PAYMENTTYPE("R"); } SetAmount(amt); // SetDiscountAmt(Env.ZERO); SetWriteOffAmt(Env.ZERO); SetIsGenerated(true); _invoice = invoice; }
public String PrepareIt() { MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID()); if (!MPeriod.IsOpen(GetCtx(), GetDateAcct(), dt.GetDocBaseType())) { _processMsg = "@PeriodClosed@"; return(_processMsg); } // is Non Business Day? if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateAcct())) { _processMsg = VAdvantage.Common.Common.NONBUSINESSDAY; return(_processMsg); } return(DocActionVariables.STATUS_INPROGRESS); }
/** * Set Invoice - no discount * @param invoice invoice */ public void SetInvoiceMultiCurrency(MInvoice invoice, Decimal Amt, int C_Currency_ID) { SetC_Invoice_ID(invoice.GetC_Invoice_ID()); SetCashType(CASHTYPE_Invoice); SetC_Currency_ID(C_Currency_ID); // Amount MDocType dt = MDocType.Get(GetCtx(), invoice.GetC_DocType_ID()); Decimal amt = Amt; if (MDocBaseType.DOCBASETYPE_APINVOICE.Equals(dt.GetDocBaseType()) || MDocBaseType.DOCBASETYPE_ARCREDITMEMO.Equals(dt.GetDocBaseType())) { amt = Decimal.Negate(amt); } SetAmount(amt); // SetDiscountAmt(Env.ZERO); SetWriteOffAmt(Env.ZERO); SetIsGenerated(true); _invoice = invoice; }
/// <summary>Add Sales Order Header for VA077 Module</summary> /// <param name="destinationorg">Destination Orgnaization id</param> /// <param name="orgId">Organization Id</param> /// <returns>bool</returns> public bool AddHeader(int destinationorg, int orgId) { VAdvantage.Model.MDocType dt = VAdvantage.Model.MDocType.Get(GetCtx(), _C_DocType_ID); MOrder newOrder = new VAdvantage.Model.MOrder(GetCtx(), 0, Get_Trx()); VAdvantage.Model.MOrder morder = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx()); newOrder.SetAD_Client_ID(GetAD_Client_ID()); if (destinationorg != 0) { newOrder.SetAD_Org_ID(destinationorg); } else { newOrder.SetAD_Org_ID(orgId); } newOrder.SetC_BPartner_ID(morder.GetC_BPartner_ID()); newOrder.SetC_BPartner_Location_ID(morder.GetC_BPartner_Location_ID()); newOrder.SetAD_User_ID(morder.GetAD_User_ID()); newOrder.SetBill_BPartner_ID(morder.GetBill_BPartner_ID()); newOrder.SetAD_OrgTrx_ID(morder.GetAD_OrgTrx_ID()); newOrder.SetBill_Location_ID(morder.GetBill_Location_ID()); newOrder.SetBill_User_ID(morder.GetBill_User_ID()); newOrder.SetM_PriceList_ID(morder.GetM_PriceList_ID()); newOrder.SetC_Currency_ID(morder.GetC_Currency_ID()); newOrder.SetSalesRep_ID(morder.GetSalesRep_ID()); newOrder.SetDescription(morder.GetDescription()); //newOrder.SetM_Warehouse_ID(morder.GetM_Warehouse_ID()); newOrder.SetC_PaymentTerm_ID(morder.GetC_PaymentTerm_ID()); newOrder.SetC_Payment_ID(morder.GetC_Payment_ID()); newOrder.SetVA009_PaymentMethod_ID(morder.GetVA009_PaymentMethod_ID()); newOrder.SetC_IncoTerm_ID(morder.GetC_IncoTerm_ID()); newOrder.SetC_Campaign_ID(morder.GetC_Campaign_ID()); newOrder.SetC_ProjectRef_ID(morder.GetC_Campaign_ID()); newOrder.SetGrandTotal(morder.GetGrandTotal()); newOrder.SetTotalLines(morder.GetTotalLines()); newOrder.Set_Value("VA077_HistoricContractDate", morder.Get_Value("VA077_HistoricContractDate")); newOrder.Set_Value("VA077_ChangeStartDate", morder.Get_Value("VA077_ChangeStartDate")); newOrder.Set_Value("VA077_ContractCPStartDate", morder.Get_Value("VA077_ContractCPStartDate")); newOrder.Set_Value("VA077_ContractCPEndDate", morder.Get_Value("VA077_ContractCPEndDate")); newOrder.Set_Value("VA077_PartialAmtCatchUp", morder.Get_Value("VA077_PartialAmtCatchUp")); newOrder.Set_Value("VA077_PartialAmtCatchUp", morder.Get_Value("VA077_PartialAmtCatchUp")); newOrder.Set_Value("VA077_OldAnnualContractTotal", morder.Get_Value("VA077_OldAnnualContractTotal")); newOrder.Set_Value("VA077_AdditionalAnnualCharge", morder.Get_Value("VA077_AdditionalAnnualCharge")); newOrder.Set_Value("VA077_NewAnnualContractTotal", morder.Get_Value("VA077_NewAnnualContractTotal")); newOrder.Set_Value("VA077_OrderRef", morder.Get_Value("VA077_OrderRef")); newOrder.Set_Value("VA077_SalesCoWorkerPer", morder.Get_Value("VA077_SalesCoWorkerPer")); newOrder.Set_Value("VA077_TotalMarginAmt", morder.Get_Value("VA077_TotalMarginAmt")); newOrder.Set_Value("VA077_SalesCoWorker", morder.Get_Value("VA077_SalesCoWorker")); newOrder.Set_Value("VA077_TotalPurchaseAmt", morder.Get_Value("VA077_TotalPurchaseAmt")); newOrder.Set_Value("VA077_TotalSalesAmt", morder.Get_Value("VA077_TotalSalesAmt")); newOrder.Set_Value("VA077_MarginPercent", morder.Get_Value("VA077_MarginPercent")); newOrder.Set_Value("VA077_IsLegalEntity", morder.Get_Value("VA077_IsLegalEntity")); newOrder.SetC_DocTypeTarget_ID(_C_DocType_ID); int C_Bpartner_ID = newOrder.GetC_BPartner_ID(); newOrder.Set_Value("IsSalesQuotation", false); // Added by Bharat on 05 Jan 2018 to set Values on Blanket Sales Order from Sales Quotation. if (dt.GetDocBaseType() == "BOO") { newOrder.Set_Value("IsBlanketTrx", true); } else // Added by Bharat on 29 March 2018 to set Blanket Order zero in case of Sales order Creation. { newOrder.SetC_Order_Blanket(0); } if (newOrder.Get_ColumnIndex("C_Order_Quotation") > 0) { newOrder.SetC_Order_Quotation(_C_Order_ID); } //Update New Order Refrence From Sales Qutation in Sales order newOrder.SetPOReference(Util.GetValueOfString(morder.GetDocumentNo())); // Added by Bharat on 31 Jan 2018 to set Inco Term from Quotation if (newOrder.Get_ColumnIndex("C_IncoTerm_ID") > 0) { newOrder.SetC_IncoTerm_ID(morder.GetC_IncoTerm_ID()); } String sqlbp = "update c_project set c_bpartner_id=" + C_Bpartner_ID + " where ref_order_id=" + _C_Order_ID + ""; int value = DB.ExecuteQuery(sqlbp, null, Get_Trx()); bool OK = newOrder.Save(); if (!OK) { //return GetReterivedError( newOrder, "Could not create new Order"); throw new Exception("Could not create new Order"); } if (OK) { string sql = "select C_Project_id from c_project where c_order_id = " + morder.GetC_Order_ID(); int C_Project_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())); if (C_Project_ID != 0) { VAdvantage.Model.X_C_Project project = new VAdvantage.Model.X_C_Project(GetCtx(), C_Project_ID, Get_Trx()); project.SetC_BPartner_ID(project.GetC_BPartnerSR_ID()); project.SetC_BPartnerSR_ID(0); if (!project.Save()) { Get_Trx().Rollback(); log.SaveError("Error on " + project.Get_TableName(), ""); } } if (dt.GetDocBaseType() == "BOO") { morder.SetC_Order_Blanket(newOrder.GetC_Order_ID()); } else { morder.SetRef_Order_ID(newOrder.GetC_Order_ID()); } newid = newOrder.GetC_Order_ID(); neworg_id = newOrder.GetAD_Org_ID(); morder.Save(); int bp = newOrder.GetC_BPartner_ID(); VAdvantage.Model.X_C_BPartner prosp = new VAdvantage.Model.X_C_BPartner(GetCtx(), bp, Get_Trx()); prosp.SetIsCustomer(true); prosp.SetIsProspect(false); if (!prosp.Save()) { Get_Trx().Rollback(); log.SaveError("Error on " + prosp.Get_TableName(), ""); } } // if (_IsCloseDocument) { VAdvantage.Model.MOrder original = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx()); //Edited by Arpit Rai on 8th of Nov,2017 if (original.GetDocStatus() != "CO") //to check if document is already completed { original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Complete); original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Complete); original.Save(); } //Arpit original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Close); original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Close); original.Save(); } docNo = newOrder.GetDocumentNo(); return(true); }
/// <summary> /// Perform Process. /// </summary> /// <returns>Message (clear text)</returns> protected override String DoIt() { log.Info("C_Order_ID=" + _C_Order_ID + ", C_DocType_ID=" + _C_DocType_ID + ", CloseDocument=" + _IsCloseDocument); if (_C_Order_ID == 0) { throw new ArgumentException("No Order"); } VAdvantage.Model.MDocType dt = VAdvantage.Model.MDocType.Get(GetCtx(), _C_DocType_ID); if (dt.Get_ID() == 0) { throw new ArgumentException("No DocType"); } if (_DateDoc == null) { _DateDoc = Util.GetValueOfDateTime(DateTime.Now); } // VAdvantage.Model.MOrder from = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx()); if (from.GetDocStatus() != "DR" && from.GetDocStatus() != "IP" && from.GetDocStatus() != "CO") { throw new Exception("Order Closed"); } //JID_1799 fromCreateSo is true if DOCBASETYPE='BOO' VAdvantage.Model.MOrder newOrder = VAdvantage.Model.MOrder.CopyFrom(from, _DateDoc, dt.GetC_DocType_ID(), false, true, null, dt.GetDocBaseType().Equals(MDocBaseType.DOCBASETYPE_BLANKETSALESORDER) ? true : false); // copy ASI newOrder.SetC_DocTypeTarget_ID(_C_DocType_ID); int C_Bpartner_ID = newOrder.GetC_BPartner_ID(); newOrder.Set_Value("IsSalesQuotation", false); // Added by Bharat on 05 Jan 2018 to set Values on Blanket Sales Order from Sales Quotation. if (dt.GetDocBaseType() == "BOO") { newOrder.Set_Value("IsBlanketTrx", true); } else // Added by Bharat on 29 March 2018 to set Blanket Order zero in case of Sales order Creation. { newOrder.SetC_Order_Blanket(0); } if (newOrder.Get_ColumnIndex("C_Order_Quotation") > 0) { newOrder.SetC_Order_Quotation(_C_Order_ID); } //Update New Order Refrence From Sales Qutation in Sales order newOrder.SetPOReference(Util.GetValueOfString(from.GetDocumentNo())); // Added by Bharat on 31 Jan 2018 to set Inco Term from Quotation if (newOrder.Get_ColumnIndex("C_IncoTerm_ID") > 0) { newOrder.SetC_IncoTerm_ID(from.GetC_IncoTerm_ID()); } String sqlbp = "update c_project set c_bpartner_id=" + C_Bpartner_ID + " where ref_order_id=" + _C_Order_ID + ""; int value = DB.ExecuteQuery(sqlbp, null, Get_Trx()); bool OK = newOrder.Save(); if (!OK) { //return GetReterivedError( newOrder, "Could not create new Order"); throw new Exception("Could not create new Order"); } if (OK) { string sql = "select C_Project_id from c_project where c_order_id = " + from.GetC_Order_ID(); int C_Project_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())); if (C_Project_ID != 0) { VAdvantage.Model.X_C_Project project = new VAdvantage.Model.X_C_Project(GetCtx(), C_Project_ID, Get_Trx()); project.SetC_BPartner_ID(project.GetC_BPartnerSR_ID()); project.SetC_BPartnerSR_ID(0); if (!project.Save()) { log.SaveError("Error on " + project.Get_TableName(), ""); } } if (dt.GetDocBaseType() == "BOO") { from.SetC_Order_Blanket(newOrder.GetC_Order_ID()); } else { from.SetRef_Order_ID(newOrder.GetC_Order_ID()); } from.Save(); int bp = newOrder.GetC_BPartner_ID(); VAdvantage.Model.X_C_BPartner prosp = new VAdvantage.Model.X_C_BPartner(GetCtx(), bp, Get_Trx()); prosp.SetIsCustomer(true); prosp.SetIsProspect(false); if (!prosp.Save()) { log.SaveError("Error on " + prosp.Get_TableName(), ""); } } // if (_IsCloseDocument) { VAdvantage.Model.MOrder original = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx()); //Edited by Arpit Rai on 8th of Nov,2017 if (original.GetDocStatus() != "CO") //to check if document is already completed { original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Complete); original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Complete); original.Save(); } //Arpit original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Close); original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Close); original.Save(); } // return(Msg.GetMsg(GetCtx(), "OrderCreatedSuccessfully") + " - " + dt.GetName() + ": " + newOrder.GetDocumentNo()); }
/// <summary> /// Process Allocation (does not update line). /// - Update and Link Invoice/Payment/Cash /// </summary> /// <param name="reverse">reverse if true allocation is reversed</param> /// <returns>C_BPartner_ID</returns> public int ProcessIt(bool reverse) { log.Fine("Reverse=" + reverse + " - " + ToString()); int C_Invoice_ID = GetC_Invoice_ID(); MInvoicePaySchedule invoiceSchedule = null; MPayment payment = null; MCashLine cashLine = null; MInvoice invoice = GetInvoice(); if (invoice != null && GetC_BPartner_ID() != invoice.GetC_BPartner_ID()) { SetC_BPartner_ID(invoice.GetC_BPartner_ID()); } // int C_Payment_ID = GetC_Payment_ID(); int C_CashLine_ID = GetC_CashLine_ID(); // Update Payment if (C_Payment_ID != 0) { payment = new MPayment(GetCtx(), C_Payment_ID, Get_TrxName()); if (GetC_BPartner_ID() != payment.GetC_BPartner_ID()) { log.Warning("C_BPartner_ID different - Invoice=" + GetC_BPartner_ID() + " - Payment=" + payment.GetC_BPartner_ID()); } if (reverse) { if (!payment.IsCashTrx()) { payment.SetIsAllocated(false); payment.Save(); } } else { if (payment.TestAllocation()) { payment.Save(); } } } // Payment - Invoice if (C_Payment_ID != 0 && invoice != null) { // Link to Invoice if (reverse) { invoice.SetC_Payment_ID(0); log.Fine("C_Payment_ID=" + C_Payment_ID + " Unlinked from C_Invoice_ID=" + C_Invoice_ID); } else if (invoice.IsPaid()) { invoice.SetC_Payment_ID(C_Payment_ID); log.Fine("C_Payment_ID=" + C_Payment_ID + " Linked to C_Invoice_ID=" + C_Invoice_ID); } // Link to Order String update = "UPDATE C_Order o " + "SET C_Payment_ID=" + (reverse ? "NULL " : "(SELECT C_Payment_ID FROM C_Invoice WHERE C_Invoice_ID=" + C_Invoice_ID + ") ") + "WHERE EXISTS (SELECT * FROM C_Invoice i " + "WHERE o.C_Order_ID=i.C_Order_ID AND i.C_Invoice_ID=" + C_Invoice_ID + ")"; if (DataBase.DB.ExecuteQuery(update, null, Get_TrxName()) > 0) { log.Fine("C_Payment_ID=" + C_Payment_ID + (reverse ? " UnLinked from" : " Linked to") + " order of C_Invoice_ID=" + C_Invoice_ID); } } // Cash - Invoice if (C_CashLine_ID != 0 && invoice != null) { // Link to Invoice if (reverse) { invoice.SetC_CashLine_ID(0); log.Fine("C_CashLine_ID=" + C_CashLine_ID + " Unlinked from C_Invoice_ID=" + C_Invoice_ID); // Set isallocated false on cashline while allocation gets deallocated assigned by Mukesh sir on 27/12/2017 MCashLine cashline = new MCashLine(GetCtx(), GetC_CashLine_ID(), Get_TrxName()); cashline.SetIsAllocated(false); cashline.Save(); } else { invoice.SetC_CashLine_ID(C_CashLine_ID); log.Fine("C_CashLine_ID=" + C_CashLine_ID + " Linked to C_Invoice_ID=" + C_Invoice_ID); } // Link to Order String update = "UPDATE C_Order o " + "SET C_CashLine_ID=" + (reverse ? "NULL " : "(SELECT C_CashLine_ID FROM C_Invoice WHERE C_Invoice_ID=" + C_Invoice_ID + ") ") + "WHERE EXISTS (SELECT * FROM C_Invoice i " + "WHERE o.C_Order_ID=i.C_Order_ID AND i.C_Invoice_ID=" + C_Invoice_ID + ")"; if (DataBase.DB.ExecuteQuery(update, null, Get_TrxName()) > 0) { log.Fine("C_CashLine_ID=" + C_CashLine_ID + (reverse ? " UnLinked from" : " Linked to") + " order of C_Invoice_ID=" + C_Invoice_ID); } } // Added by Bharat- Update Discrepancy amount on Invoice. if (C_Payment_ID == 0 && C_CashLine_ID == 0 && invoice != null) { if (invoice.Get_ColumnIndex("DiscrepancyAmt") >= 0) { decimal desAmt = invoice.GetDiscrepancyAmt(); decimal desAjusted = invoice.GetDiscrepancyAdjusted(); decimal allocAmt = Math.Abs(GetAmount()); // absolute if (reverse) { if (allocAmt > desAjusted) { desAmt = Decimal.Add(desAjusted, desAmt); desAjusted = 0; } else { desAmt = Decimal.Add(desAmt, allocAmt); desAjusted = Decimal.Subtract(desAjusted, allocAmt); } invoice.SetDiscrepancyAmt(desAmt); invoice.SetDiscrepancyAdjusted(desAjusted); if (desAmt > 0) { invoice.SetIsInDispute(true); } } else { if (allocAmt > desAmt) { desAjusted = Decimal.Add(desAjusted, desAmt); desAmt = 0; } else { desAjusted = Decimal.Add(desAjusted, allocAmt); desAmt = Decimal.Subtract(desAmt, allocAmt); } invoice.SetDiscrepancyAmt(desAmt); invoice.SetDiscrepancyAdjusted(desAjusted); if (desAmt == 0) { invoice.SetIsInDispute(false); } } if (!invoice.Save()) { log.Log(Level.SEVERE, "Invoice not updated - " + invoice); } } } // Update Balance / Credit used - Counterpart of MInvoice.completeIt if (invoice != null) { if (invoice.TestAllocation() && !invoice.Save()) { log.Log(Level.SEVERE, "Invoice not updated - " + invoice); } else if (reverse) { // added by Amit // if payment Management module downloaded and Invoice Schedule id available on Allocation then mark ispaid on schedule as false if (Env.IsModuleInstalled("VA009_")) { MAllocationHdr allocHdr = new MAllocationHdr(GetCtx(), GetC_AllocationHdr_ID(), Get_Trx()); decimal payAmt = 0; MDocType doctype = null; MCurrency currency = new MCurrency(GetCtx(), invoice.GetC_Currency_ID(), null); if (GetC_InvoicePaySchedule_ID() != 0 && !invoice.IsPaid()) { invoiceSchedule = new MInvoicePaySchedule(GetCtx(), GetC_InvoicePaySchedule_ID(), Get_TrxName()); invoiceSchedule.SetVA009_IsPaid(false); // when we update schedule paid as False, then update payment method and related fields on schedule as on Invoice Header if (reverse) { invoiceSchedule.SetVA009_PaymentMethod_ID(invoice.GetVA009_PaymentMethod_ID()); DataSet dsPaymentMethod = DB.ExecuteDataset(@"SELECT VA009_PaymentMode, VA009_PaymentType, VA009_PaymentTrigger FROM VA009_PaymentMethod WHERE IsActive = 'Y' AND VA009_PaymentMethod_ID = " + invoice.GetVA009_PaymentMethod_ID(), null, Get_Trx()); if (dsPaymentMethod != null && dsPaymentMethod.Tables.Count > 0 && dsPaymentMethod.Tables[0].Rows.Count > 0) { if (!String.IsNullOrEmpty(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentMode"]))) { invoiceSchedule.SetVA009_PaymentMode(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentMode"])); } if (!String.IsNullOrEmpty(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentType"]))) { invoiceSchedule.SetVA009_PaymentType(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentType"])); } invoiceSchedule.SetVA009_PaymentTrigger(Util.GetValueOfString(dsPaymentMethod.Tables[0].Rows[0]["VA009_PaymentTrigger"])); } dsPaymentMethod = null; } if (reverse && payment != null) { #region Handle for Payment & Invoice Allocation doctype = new MDocType(GetCtx(), invoice.GetC_DocType_ID(), null); // convert (payment amount / Amount from View Allocation) to invoice currency amount then subtract Paid invoice amount to calculated amount if (doctype.GetDocBaseType() == "ARC" || doctype.GetDocBaseType() == "APC") { if (payment.GetC_Invoice_ID() != 0) { // when payment created with invoice refernce direct // convert payment amount in invoice amt with payment date and payment conversion type payAmt = MConversionRate.Convert(GetCtx(), Decimal.Negate(Decimal.Add(Decimal.Add(payment.GetPayAmt(), payment.GetDiscountAmt()), payment.GetWriteOffAmt())), payment.GetC_Currency_ID(), invoice.GetC_Currency_ID(), payment.GetDateAcct(), payment.GetC_ConversionType_ID(), GetAD_Client_ID(), GetAD_Org_ID()); } else { // when payment created with Payment Allocate entry OR // when we match payment with invoice through Payment Allocation form // convert payment amount in invoice amt with view allocation date payAmt = MConversionRate.Convert(GetCtx(), Decimal.Negate(Decimal.Add(Decimal.Add(GetAmount(), GetDiscountAmt()), GetWriteOffAmt())), allocHdr.GetC_Currency_ID(), invoice.GetC_Currency_ID(), allocHdr.GetDateAcct(), invoice.GetC_ConversionType_ID(), GetAD_Client_ID(), GetAD_Org_ID()); if (doctype.GetDocBaseType() == "APC") { payAmt = Decimal.Negate(payAmt); } } } else { if (payment.GetC_Invoice_ID() != 0) { // when we create payment with invoice reference direct // convert payment amount in invoice amt with payment date and payment conversion type payAmt = MConversionRate.Convert(GetCtx(), Decimal.Add(Decimal.Add(payment.GetPayAmt(), payment.GetDiscountAmt()), payment.GetWriteOffAmt()), payment.GetC_Currency_ID(), invoice.GetC_Currency_ID(), payment.GetDateAcct(), payment.GetC_ConversionType_ID(), GetAD_Client_ID(), GetAD_Org_ID()); } else { // when payment created with Payment Allocate entry Or // when we match payment with invoice through Payment Allocation form // convert payment amount in invoice amt with view allocation date payAmt = MConversionRate.Convert(GetCtx(), Decimal.Add(Decimal.Add(GetAmount(), GetDiscountAmt()), GetWriteOffAmt()), allocHdr.GetC_Currency_ID(), invoice.GetC_Currency_ID(), allocHdr.GetDateAcct(), invoice.GetC_ConversionType_ID(), GetAD_Client_ID(), GetAD_Org_ID()); if (doctype.GetDocBaseType() == "API") { payAmt = Decimal.Negate(payAmt); } } } invoiceSchedule.SetVA009_PaidAmntInvce(Decimal.Round(Decimal.Subtract(invoiceSchedule.GetVA009_PaidAmntInvce(), payAmt), currency.GetStdPrecision())); // during reversal, if Invoice paid amount <> 0 then reduce that amount from next schedule try { if (invoiceSchedule.GetVA009_PaidAmntInvce() != 0) { int no = Util.GetValueOfInt(DB.ExecuteQuery(@"UPDATE C_InvoicePaySchedule SET VA009_PaidAmntInvce = NVL(VA009_PaidAmntInvce , 0) + " + Decimal.Round(invoiceSchedule.GetVA009_PaidAmntInvce(), currency.GetStdPrecision()) + @" , VA009_PaidAmnt = NVL(VA009_PaidAmnt , 0) + " + Decimal.Round(MConversionRate.ConvertBase(GetCtx(), invoiceSchedule.GetVA009_PaidAmntInvce(), invoice.GetC_Currency_ID(), invoice.GetDateAcct(), invoice.GetC_ConversionType_ID(), GetAD_Client_ID(), GetAD_Org_ID()), currency.GetStdPrecision()) + @" WHERE C_InvoicePaySchedule_ID = ( SELECT MIN(C_InvoicePaySchedule_ID) FROM C_InvoicePaySchedule WHERE IsActive = 'Y' AND VA009_IsPaid = 'N' AND C_Invoice_ID = " + invoice.GetC_Invoice_ID() + @" AND C_InvoicePaySchedule_ID <> " + GetC_InvoicePaySchedule_ID() + " ) ", null, Get_Trx())); // set paid invoice amount = 0, no > 0 bcz this is not last schedule if (no > 0) { invoiceSchedule.SetVA009_PaidAmntInvce(0); } } } catch { } // convert invoice paid amount to base currency amount invoiceSchedule.SetVA009_PaidAmnt(Decimal.Round(MConversionRate.ConvertBase(GetCtx(), invoiceSchedule.GetVA009_PaidAmntInvce(), invoice.GetC_Currency_ID(), invoice.GetDateAcct(), invoice.GetC_ConversionType_ID(), GetAD_Client_ID(), GetAD_Org_ID()), currency.GetStdPrecision())); // set Currency Variance amount as 0, when we reverse paymnet/ cash journalor allocation against this schedule invoiceSchedule.SetVA009_Variance(0); // remove linking of Payment from schedule invoiceSchedule.SetC_Payment_ID(0); #endregion } else if (reverse && C_CashLine_ID > 0) { #region Handle fo Cash Journal & Invoice Allocation doctype = new MDocType(GetCtx(), invoice.GetC_DocType_ID(), null); cashLine = new MCashLine(GetCtx(), C_CashLine_ID, Get_Trx()); // convert cash amount to invoice currency amount with allocation date then subtract Paid invoice amount to calculated amount if (doctype.GetDocBaseType() == "ARC" || doctype.GetDocBaseType() == "API") { payAmt = Decimal.Negate(Decimal.Add(Decimal.Add(GetAmount(), GetDiscountAmt()), GetWriteOffAmt())); payAmt = MConversionRate.Convert(GetCtx(), payAmt, allocHdr.GetC_Currency_ID(), invoice.GetC_Currency_ID(), allocHdr.GetDateAcct(), invoice.GetC_ConversionType_ID(), GetAD_Client_ID(), GetAD_Org_ID()); invoiceSchedule.SetVA009_PaidAmntInvce(Decimal.Round(Decimal.Subtract(invoiceSchedule.GetVA009_PaidAmntInvce(), payAmt), currency.GetStdPrecision())); } else { payAmt = Decimal.Add(Decimal.Add(GetAmount(), GetDiscountAmt()), GetWriteOffAmt()); payAmt = MConversionRate.Convert(GetCtx(), payAmt, allocHdr.GetC_Currency_ID(), invoice.GetC_Currency_ID(), allocHdr.GetDateAcct(), invoice.GetC_ConversionType_ID(), GetAD_Client_ID(), GetAD_Org_ID()); invoiceSchedule.SetVA009_PaidAmntInvce(Decimal.Round(Decimal.Subtract(invoiceSchedule.GetVA009_PaidAmntInvce(), payAmt), currency.GetStdPrecision())); } // during reversal, if Invoice paid amount <> 0 then reduce that amount from next schedule try { if (invoiceSchedule.GetVA009_PaidAmntInvce() != 0) { int no = Util.GetValueOfInt(DB.ExecuteQuery(@"UPDATE C_InvoicePaySchedule SET VA009_PaidAmntInvce = NVL(VA009_PaidAmntInvce , 0) + " + Decimal.Round(invoiceSchedule.GetVA009_PaidAmntInvce(), currency.GetStdPrecision()) + @" , VA009_PaidAmnt = NVL(VA009_PaidAmnt , 0) + " + Decimal.Round(MConversionRate.ConvertBase(GetCtx(), invoiceSchedule.GetVA009_PaidAmntInvce(), invoice.GetC_Currency_ID(), invoice.GetDateAcct(), invoice.GetC_ConversionType_ID(), GetAD_Client_ID(), GetAD_Org_ID()), currency.GetStdPrecision()) + @" WHERE C_InvoicePaySchedule_ID = ( SELECT MIN(C_InvoicePaySchedule_ID) FROM C_InvoicePaySchedule WHERE IsActive = 'Y' AND VA009_IsPaid = 'N' AND C_Invoice_ID = " + invoice.GetC_Invoice_ID() + @" AND C_InvoicePaySchedule_ID <> " + GetC_InvoicePaySchedule_ID() + " ) ", null, Get_Trx())); // set paid invoice amount = 0, no > 0 bcz this is not last schedule if (no > 0) { invoiceSchedule.SetVA009_PaidAmntInvce(0); } } } catch { } // convert invoice paid amount to base currency amount invoiceSchedule.SetVA009_PaidAmnt(Decimal.Round(MConversionRate.ConvertBase(GetCtx(), invoiceSchedule.GetVA009_PaidAmntInvce(), invoice.GetC_Currency_ID(), invoice.GetDateAcct(), invoice.GetC_ConversionType_ID(), GetAD_Client_ID(), GetAD_Org_ID()), currency.GetStdPrecision())); // set Currency Variance amount as 0, when we reverse paymnet/ cash journalor allocation against this schedule invoiceSchedule.SetVA009_Variance(0); // remove linking of cash line from schedule invoiceSchedule.SetC_CashLine_ID(0); #endregion } else { invoiceSchedule.SetVA009_PaidAmntInvce(0); invoiceSchedule.SetVA009_PaidAmnt(0); // set Currency Variance amount as 0, when we reverse paymnet/ cash journalor allocation against this schedule invoiceSchedule.SetVA009_Variance(0); } if (!invoiceSchedule.Save(Get_TrxName())) { log.Log(Level.SEVERE, "Invoice Pay Schedule not updated - " + invoice); } } } } } return(GetC_BPartner_ID()); }
public bool ReverseCorrectIt() { MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID()); if (!MPeriod.IsOpen(GetCtx(), GetDateAcct(), dt.GetDocBaseType())) { _processMsg = "@PeriodClosed@"; return(false); } // is Non Business Day? if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateAcct())) { _processMsg = VAdvantage.Common.Common.NONBUSINESSDAY; return(false); } //set delievered = true //int no = Util.GetValueOfInt(DB.ExecuteScalar("UPDATE VA024_t_ObsoleteInventory SET VA024_ISDELIVERED = 'Y' , VA024_REMAININGQTY=0 WHERE VA024_ObsoleteInventory_ID = " + GetVA024_ObsoleteInventory_ID(), null, Get_Trx())); // Create Reversal Line MCostAllocation reversal = new MCostAllocation(GetCtx(), 0, Get_Trx()); CopyValues(this, reversal); reversal.SetClientOrg(this); // reversal.SetDocumentNo(GetDocumentNo() + REVERSE_INDICATOR); reversal.SetDocStatus(DOCSTATUS_Drafted); reversal.SetDocAction(DOCACTION_Complete); // reversal.SetIsProcessed(false); reversal.SetPosted(false); //reversal.SetProcessing(false); reversal.SetDescription(GetDescription()); reversal.AddDescription("{->" + GetDocumentNo() + ")"); reversal.SetAllocationAmt(Decimal.Negate(GetAllocationAmt())); reversal.Save(Get_Trx()); // Copy lines MCostAllocationLine reversalLine = null; MCostAllocationLine[] lines = GetLines(false); for (int i = 0; i < lines.Length; i++) { MCostAllocationLine line = lines[i]; reversalLine = new MCostAllocationLine(GetCtx(), 0, Get_Trx()); CopyValues(line, reversalLine); reversalLine.SetClientOrg(this); reversalLine.SetM_CostAllocation_ID(reversal.GetM_CostAllocation_ID()); reversalLine.SetIsProcessed(true); reversalLine.SetAmount(Decimal.Negate(line.GetAmount())); reversalLine.Save(Get_Trx()); } reversal.CloseIt(); _processMsg = reversal.GetDocumentNo(); reversal.SetIsProcessed(true); reversal.SetDocStatus(DOCSTATUS_Reversed); reversal.SetDocAction(DOCACTION_None); reversal.Save(Get_Trx()); this.AddDescription("(" + GetDocumentNo() + "<-)"); SetDocAction(DOCACTION_None); SetDocStatus(DOCSTATUS_Reversed); Save(Get_Trx()); return(true); }
/*Validate Document Type compatability * @return Error message or null if valid */ public String Validate() { MDocType dt = GetDocType(); if (dt == null) { log.Log(Level.SEVERE, "No DocType=" + GetC_DocType_ID()); SetIsValid(false); return("No Document Type"); } MDocType c_dt = GetCounterDocType(); if (c_dt == null) { log.Log(Level.SEVERE, "No Counter DocType=" + GetCounter_C_DocType_ID()); SetIsValid(false); return("No Counter Document Type"); } // String dtBT = dt.GetDocBaseType(); String c_dtBT = c_dt.GetDocBaseType(); log.Fine(dtBT + " -> " + c_dtBT); // SO / PO if ((MDocBaseType.DOCBASETYPE_SALESORDER.Equals(dtBT) && MDocBaseType.DOCBASETYPE_PURCHASEORDER.Equals(c_dtBT)) || (MDocBaseType.DOCBASETYPE_SALESORDER.Equals(c_dtBT) && MDocBaseType.DOCBASETYPE_PURCHASEORDER.Equals(dtBT))) { SetIsValid(true); } // AP/AR Invoice else if ((MDocBaseType.DOCBASETYPE_APINVOICE.Equals(dtBT) && MDocBaseType.DOCBASETYPE_ARINVOICE.Equals(c_dtBT)) || (MDocBaseType.DOCBASETYPE_APINVOICE.Equals(c_dtBT) && MDocBaseType.DOCBASETYPE_ARINVOICE.Equals(dtBT))) { SetIsValid(true); } // Shipment else if ((MDocBaseType.DOCBASETYPE_MATERIALDELIVERY.Equals(dtBT) && MDocBaseType.DOCBASETYPE_MATERIALRECEIPT.Equals(c_dtBT)) || (MDocBaseType.DOCBASETYPE_MATERIALDELIVERY.Equals(c_dtBT) && MDocBaseType.DOCBASETYPE_MATERIALRECEIPT.Equals(dtBT))) { SetIsValid(true); } // AP/AR CreditMemo else if ((MDocBaseType.DOCBASETYPE_APCREDITMEMO.Equals(dtBT) && MDocBaseType.DOCBASETYPE_ARCREDITMEMO.Equals(c_dtBT)) || (MDocBaseType.DOCBASETYPE_APCREDITMEMO.Equals(c_dtBT) && MDocBaseType.DOCBASETYPE_ARCREDITMEMO.Equals(dtBT))) { SetIsValid(true); } // Receipt / Payment else if ((MDocBaseType.DOCBASETYPE_ARRECEIPT.Equals(dtBT) && MDocBaseType.DOCBASETYPE_APPAYMENT.Equals(c_dtBT)) || (MDocBaseType.DOCBASETYPE_ARRECEIPT.Equals(c_dtBT) && MDocBaseType.DOCBASETYPE_APPAYMENT.Equals(dtBT))) { SetIsValid(true); } else { log.Warning("NOT - " + dtBT + " -> " + c_dtBT); SetIsValid(false); return("Not valid"); } // Counter should have document numbering if (!c_dt.IsDocNoControlled()) { return("Counter Document Type should be automatically Document Number controlled"); } return(null); }
/// <summary> /// Perform Process. /// </summary> /// <returns>Message (clear text)</returns> protected override String DoIt() { //log.Info("C_Order_ID=" + _C_Order_ID // + ", C_DocType_ID=" + _C_DocType_ID // + ", CloseDocument=" + _IsCloseDocument); //if (_C_Order_ID == 0) //{ // throw new ArgumentException("No Order"); //} //MDocType dt = MDocType.Get(GetCtx(), _C_DocType_ID); //if (dt.Get_ID() == 0) //{ // throw new ArgumentException("No DocType"); //} //if (_DateDoc == null) //{ // _DateDoc = DateTime.Now; // //Util.GetValueOfDateTime(new DateTime(CommonFunctions.CurrentTimeMillis())); //} //// //MOrder from = new MOrder(GetCtx(), _C_Order_ID, Get_Trx()); //MOrder newOrder = MOrder.CopyFrom(from, _DateDoc, // dt.GetC_DocType_ID(), false, true, null); // copy ASI //newOrder.SetC_DocTypeTarget_ID(_C_DocType_ID); //bool OK = newOrder.Save (); //if (!OK) //{ // throw new Exception("Could not create new Order"); //} //// //if (_IsCloseDocument) //{ // MOrder original = new MOrder(GetCtx(), _C_Order_ID, Get_Trx()); // original.SetDocAction(MOrder.DOCACTION_Complete); // original.ProcessIt(MOrder.DOCACTION_Complete); // original.Save(); // original.SetDocAction(MOrder.DOCACTION_Close); // original.ProcessIt(MOrder.DOCACTION_Close); // original.Save(); //} //// //return dt.GetName() + ": " + newOrder.GetDocumentNo(); log.Info("C_Order_ID=" + _C_Order_ID + ", C_DocType_ID=" + _C_DocType_ID + ", CloseDocument=" + _IsCloseDocument); if (_C_Order_ID == 0) { throw new ArgumentException("No Order"); } VAdvantage.Model.MDocType dt = VAdvantage.Model.MDocType.Get(GetCtx(), _C_DocType_ID); if (dt.Get_ID() == 0) { throw new ArgumentException("No DocType"); } if (_DateDoc == null) { _DateDoc = Util.GetValueOfDateTime(DateTime.Now); } // VAdvantage.Model.MOrder from = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx()); VAdvantage.Model.MOrder newOrder = VAdvantage.Model.MOrder.CopyFrom(from, _DateDoc, dt.GetC_DocType_ID(), false, true, null); // copy ASI newOrder.SetC_DocTypeTarget_ID(_C_DocType_ID); //Update New Order Refrence From Sales Qutation in Sales order newOrder.SetPOReference(Util.GetValueOfString(from.GetDocumentNo())); int C_Bpartner_ID = newOrder.GetC_BPartner_ID(); String sqlbp = "update c_project set c_bpartner_id=" + C_Bpartner_ID + " where ref_order_id=" + _C_Order_ID + ""; int value = DB.ExecuteQuery(sqlbp, null, Get_Trx()); bool OK = newOrder.Save(); if (!OK) { throw new Exception("Could not create new Order"); } if (OK) { string sql = "select C_Project_id from c_project where c_order_id = " + from.GetC_Order_ID(); int C_Project_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())); if (C_Project_ID != 0) { VAdvantage.Model.X_C_Project project = new VAdvantage.Model.X_C_Project(GetCtx(), C_Project_ID, Get_Trx()); project.SetC_BPartner_ID(project.GetC_BPartnerSR_ID()); project.SetC_BPartnerSR_ID(0); if (!project.Save()) { } } from.SetRef_Order_ID(newOrder.GetC_Order_ID()); from.Save(); int bp = newOrder.GetC_BPartner_ID(); VAdvantage.Model.X_C_BPartner prosp = new VAdvantage.Model.X_C_BPartner(GetCtx(), bp, Get_Trx()); prosp.SetIsCustomer(true); prosp.SetIsProspect(false); prosp.Save(); } // if (_IsCloseDocument) { VAdvantage.Model.MOrder original = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx()); original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Complete); original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Complete); original.Save(); original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Close); original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Close); original.Save(); } // return(Msg.GetMsg(GetCtx(), "OrderCreatedSuuccessfully")); //return dt.GetName() + ": " + newOrder.GetDocumentNo(); }
} // invalidateIt /// <summary> /// Prepare Document /// </summary> /// <returns>new status (In Progress or Invalid) </returns> public String PrepareIt() { log.Info(ToString()); m_processMsg = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_BEFORE_PREPARE); if (m_processMsg != null) { return(DocActionVariables.STATUS_INVALID); } MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID()); // Std Period open? if (!MPeriod.IsOpen(GetCtx(), GetDateAcct(), dt.GetDocBaseType())) { m_processMsg = "@PeriodClosed@"; return(DocActionVariables.STATUS_INVALID); } // is Non Business Day? // JID_1205: At the trx, need to check any non business day in that org. if not fund then check * org. if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateAcct(), GetAD_Org_ID())) { m_processMsg = Common.Common.NONBUSINESSDAY; return(DocActionVariables.STATUS_INVALID); } // JID_0521 - Restrict if debit and credit amount is not equal.-Mohit-12-jun-2019. if (GetTotalCr() != GetTotalDr()) { m_processMsg = Msg.GetMsg(GetCtx(), "DBAndCRAmtNotEqual"); return(DocActionVariables.STATUS_INVALID); } // Add up Amounts & prepare them MJournal[] journals = GetJournals(false); if (journals.Length == 0) { m_processMsg = "@NoLines@"; return(DocActionVariables.STATUS_INVALID); } Decimal TotalDr = Env.ZERO; Decimal TotalCr = Env.ZERO; for (int i = 0; i < journals.Length; i++) { MJournal journal = journals[i]; if (!journal.IsActive()) { continue; } // Prepare if not closed if (DOCSTATUS_Closed.Equals(journal.GetDocStatus()) || DOCSTATUS_Voided.Equals(journal.GetDocStatus()) || DOCSTATUS_Reversed.Equals(journal.GetDocStatus()) || DOCSTATUS_Completed.Equals(journal.GetDocStatus())) { ; } else { String status = journal.PrepareIt(); if (!DocActionVariables.STATUS_INPROGRESS.Equals(status)) { journal.SetDocStatus(status); journal.Save(); m_processMsg = journal.GetProcessMsg(); return(status); } journal.SetDocStatus(DOCSTATUS_InProgress); journal.Save(); } // //TotalDr = TotalDr.add(journal.getTotalDr()); TotalDr = Decimal.Add(TotalDr, journal.GetTotalDr()); TotalCr = Decimal.Add(TotalCr, journal.GetTotalCr()); } SetTotalDr(TotalDr); SetTotalCr(TotalCr); // Control Amount if (Env.ZERO.CompareTo(GetControlAmt()) != 0 && GetControlAmt().CompareTo(GetTotalDr()) != 0) { m_processMsg = "@ControlAmtError@"; return(DocActionVariables.STATUS_INVALID); } // Add up Amounts m_justPrepared = true; return(DocActionVariables.STATUS_INPROGRESS); } // prepareIt
} // invalidateIt /// <summary> /// Prepare Document /// </summary> /// <returns>new status (In Progress or Invalid) </returns> public String PrepareIt() { log.Info(ToString()); m_processMsg = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_BEFORE_PREPARE); if (m_processMsg != null) { return(DocActionVariables.STATUS_INVALID); } MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID()); // Get Period MPeriod period = MPeriod.Get(GetCtx(), GetDateAcct()); if (period == null) { log.Warning("No Period for " + GetDateAcct()); m_processMsg = "@PeriodNotFound@"; return(DocActionVariables.STATUS_INVALID); } // Standard Period if (period.GetC_Period_ID() != GetC_Period_ID() && period.IsStandardPeriod()) { m_processMsg = "@PeriodNotValid@"; return(DocActionVariables.STATUS_INVALID); } Boolean open = period.IsOpen(dt.GetDocBaseType()); if (!open) { log.Warning(period.GetName() + ": Not open for " + dt.GetDocBaseType() + " (" + GetDateAcct() + ")"); m_processMsg = "@PeriodClosed@"; return(DocActionVariables.STATUS_INVALID); } // Lines MJournalLine[] lines = GetLines(true); if (lines.Length == 0) { m_processMsg = "@NoLines@"; return(DocActionVariables.STATUS_INVALID); } // Add up Amounts Decimal AmtSourceDr = Env.ZERO; Decimal AmtSourceCr = Env.ZERO; for (int i = 0; i < lines.Length; i++) { MJournalLine line = lines[i]; if (!IsActive()) { continue; } // if (line.IsDocControlled()) { m_processMsg = "@DocControlledError@ - @Line@=" + line.GetLine() + " - " + line.GetAccountElementValue(); return(DocActionVariables.STATUS_INVALID); } // AmtSourceDr = Decimal.Add(AmtSourceDr, line.GetAmtSourceDr()); AmtSourceCr = Decimal.Add(AmtSourceCr, line.GetAmtSourceCr()); } SetTotalDr(AmtSourceDr); SetTotalCr(AmtSourceCr); // Control Amount if (Env.ZERO.CompareTo(GetControlAmt()) != 0 && GetControlAmt().CompareTo(GetTotalDr()) != 0) { m_processMsg = "@ControlAmtError@"; return(DocActionVariables.STATUS_INVALID); } // Unbalanced Jornal & Not Suspense if (AmtSourceDr.CompareTo(AmtSourceCr) != 0) { MAcctSchemaGL gl = MAcctSchemaGL.Get(GetCtx(), GetC_AcctSchema_ID()); if (gl == null || !gl.IsUseSuspenseBalancing()) { m_processMsg = "@UnbalancedJornal@"; return(DocActionVariables.STATUS_INVALID); } } if (!DOCACTION_Complete.Equals(GetDocAction())) { SetDocAction(DOCACTION_Complete); } m_justPrepared = true; return(DocActionVariables.STATUS_INPROGRESS); } // prepareIt
public bool ReActivateIt() { try { log.Info(ToString()); MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID()); String DocSubTypeSO = dt.GetDocSubTypeSO(); // Replace Prepay with POS to revert all doc if (MDocType.DOCSUBTYPESO_PrepayOrder.Equals(DocSubTypeSO)) { MDocType newDT = null; MDocType[] dts = MDocType.GetOfClient(GetCtx()); for (int i = 0; i < dts.Length; i++) { MDocType type = dts[i]; if (MDocType.DOCSUBTYPESO_PrepayOrder.Equals(type.GetDocSubTypeSO())) { if (type.IsDefault() || newDT == null) { newDT = type; } } } if (newDT == null) { return(false); } else { SetC_DocType_ID(newDT.GetC_DocType_ID()); //SetIsReturnTrx(newDT.IsReturnTrx()); } } // PO - just re-open //if (!IsSOTrx()) //{ // log.Info("Existing documents not modified - " + dt); //} // Reverse Direct Documents else if (MDocType.DOCSUBTYPESO_OnCreditOrder.Equals(DocSubTypeSO) || // (W)illCall(I)nvoice MDocType.DOCSUBTYPESO_WarehouseOrder.Equals(DocSubTypeSO) || // (W)illCall(P)ickup MDocType.DOCSUBTYPESO_POSOrder.Equals(DocSubTypeSO)) // (W)alkIn(R)eceipt { if (!CreateReversals()) { return(false); } } else { log.Info("Existing documents not modified - SubType=" + DocSubTypeSO); } SetDocAction(DOCACTION_Complete); SetProcessed(false); } catch { //ShowMessage.Error("MOrder", null, "SetBPartner"); } return(true); }
} // invalidateIt /// <summary> /// Prepare Document /// </summary> /// <returns>new status (In Progress or Invalid) </returns> public String PrepareIt() { log.Info(ToString()); m_processMsg = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_BEFORE_PREPARE); if (m_processMsg != null) { return(DocActionVariables.STATUS_INVALID); } MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID()); // Get Period MPeriod period = MPeriod.Get(GetCtx(), GetDateAcct()); if (period == null) { log.Warning("No Period for " + GetDateAcct()); m_processMsg = "@PeriodNotFound@"; return(DocActionVariables.STATUS_INVALID); } // Standard Period if (period.GetC_Period_ID() != GetC_Period_ID() && period.IsStandardPeriod()) { m_processMsg = "@PeriodNotValid@"; return(DocActionVariables.STATUS_INVALID); } Boolean open = period.IsOpen(dt.GetDocBaseType()); if (!open) { log.Warning(period.GetName() + ": Not open for " + dt.GetDocBaseType() + " (" + GetDateAcct() + ")"); m_processMsg = "@PeriodClosed@"; return(DocActionVariables.STATUS_INVALID); } // Lines MJournalLine[] lines = GetLines(true); if (lines.Length == 0) { m_processMsg = "@NoLines@"; return(DocActionVariables.STATUS_INVALID); } //Manish 18/7/2016 .. Because if line dimention (Amount) column sum is not equals to debit or credit value complete process will not done. int journalDRAndCR = 0; string getlinevalues = "SELECT NVL(ElementType,null) AS ElementType,AmtSourceDr,AmtAcctCr,AmtSourceCr,GL_JournalLine_ID FROM GL_JournalLine where GL_Journal_ID=" + Get_Value("GL_Journal_ID"); DataSet dts = DB.ExecuteDataset(getlinevalues, null, null); if (dts != null && dts.Tables[0].Rows.Count > 0) { for (int i = 0; i < dts.Tables[0].Rows.Count; i++) { journalDRAndCR = 0; if (dts.Tables[0].Rows[i]["ElementType"].ToString() == "") { continue; } if (Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceDr"]) > 0) { journalDRAndCR = Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceDr"]); } else { if (Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceCr"]) > 0) { journalDRAndCR = Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceCr"]); } } string getlineval = "SELECT SUM(amount) FROM gl_linedimension where GL_JournalLine_ID=" + Convert.ToInt32(dts.Tables[0].Rows[i]["GL_JournalLine_ID"]); int count = Util.GetValueOfInt(DB.ExecuteScalar(getlineval)); if (journalDRAndCR != count) { m_processMsg = "@AmountNotMatch@"; return(DocActionVariables.STATUS_INVALID); } } } // Add up Amounts Decimal AmtSourceDr = Env.ZERO; Decimal AmtSourceCr = Env.ZERO; for (int i = 0; i < lines.Length; i++) { MJournalLine line = lines[i]; if (!IsActive()) { continue; } // if (line.IsDocControlled()) { m_processMsg = "@DocControlledError@ - @Line@=" + line.GetLine() + " - " + line.GetAccountElementValue(); return(DocActionVariables.STATUS_INVALID); } // AmtSourceDr = Decimal.Add(AmtSourceDr, line.GetAmtAcctDr()); AmtSourceCr = Decimal.Add(AmtSourceCr, line.GetAmtAcctCr()); } SetTotalDr(AmtSourceDr); SetTotalCr(AmtSourceCr); // Control Amount if (Env.ZERO.CompareTo(GetControlAmt()) != 0 && GetControlAmt().CompareTo(GetTotalDr()) != 0) { m_processMsg = "@ControlAmtError@"; return(DocActionVariables.STATUS_INVALID); } // Unbalanced Jornal & Not Suspense if (AmtSourceDr.CompareTo(AmtSourceCr) != 0) { MAcctSchemaGL gl = MAcctSchemaGL.Get(GetCtx(), GetC_AcctSchema_ID()); if (gl == null || !gl.IsUseSuspenseBalancing()) { m_processMsg = "@UnbalancedJornal@"; return(DocActionVariables.STATUS_INVALID); } } if (!DOCACTION_Complete.Equals(GetDocAction())) { SetDocAction(DOCACTION_Complete); } m_justPrepared = true; return(DocActionVariables.STATUS_INPROGRESS); } // prepareIt
} // toString /// <summary> /// Get Document Info /// </summary> /// <returns>document info (untranslated)</returns> public String GetDocumentInfo() { MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID()); return(dt.GetName() + " " + GetDocumentNo()); } // getDocumentInfo
/// <summary> /// Perform Process. /// </summary> /// <returns>Message (clear text)</returns> protected override String DoIt() { log.Info("C_Order_ID=" + _C_Order_ID + ", C_DocType_ID=" + _C_DocType_ID + ", CloseDocument=" + _IsCloseDocument); if (_C_Order_ID == 0) { throw new ArgumentException("No Order"); } VAdvantage.Model.MDocType dt = VAdvantage.Model.MDocType.Get(GetCtx(), _C_DocType_ID); if (dt.Get_ID() == 0) { throw new ArgumentException("No DocType"); } if (_DateDoc == null) { _DateDoc = Util.GetValueOfDateTime(DateTime.Now); } // VAdvantage.Model.MOrder from = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx()); if (from.GetDocStatus() != "DR" && from.GetDocStatus() != "IP" && from.GetDocStatus() != "CO") { throw new Exception("Order Closed"); } //Develop by Deekshant For check VA077 Module For spilt the Sales Order if (VAdvantage.Utility.Env.IsModuleInstalled("VA077_")) { //Check Destination Organization in c_orderline string str = "SELECT DISTINCT(VA077_DestinationOrg), AD_Org_Id FROM C_OrderLine WHERE C_Order_ID=" + _C_Order_ID; DataSet dts = DB.ExecuteDataset(str, null, Get_Trx()); if (dts != null && dts.Tables[0].Rows.Count > 0) { for (int i = 0; i < dts.Tables[0].Rows.Count; i++) { int destinationorg = Util.GetValueOfInt(dts.Tables[0].Rows[i]["VA077_DestinationOrg"]); // VAdvantage.Model.MOrder newOrder = new VAdvantage.Model.MOrder(GetCtx(), 0, Get_Trx()); int orgId = Util.GetValueOfInt(dts.Tables[0].Rows[i]["AD_Org_Id"]); AddHeader(destinationorg, orgId); Addline(destinationorg, orgId); } } } else { //JID_1799 fromCreateSo is true if DOCBASETYPE='BOO' VAdvantage.Model.MOrder newOrder = VAdvantage.Model.MOrder.CopyFrom(from, _DateDoc, dt.GetC_DocType_ID(), false, true, null, dt.GetDocBaseType().Equals(MDocBaseType.DOCBASETYPE_BLANKETSALESORDER) ? true : false); // copy ASI newOrder.SetC_DocTypeTarget_ID(_C_DocType_ID); int C_Bpartner_ID = newOrder.GetC_BPartner_ID(); newOrder.Set_Value("IsSalesQuotation", false); // Added by Bharat on 05 Jan 2018 to set Values on Blanket Sales Order from Sales Quotation. if (dt.GetDocBaseType() == "BOO") { newOrder.Set_Value("IsBlanketTrx", true); } else // Added by Bharat on 29 March 2018 to set Blanket Order zero in case of Sales order Creation. { newOrder.SetC_Order_Blanket(0); } if (newOrder.Get_ColumnIndex("C_Order_Quotation") > 0) { newOrder.SetC_Order_Quotation(_C_Order_ID); } //Update New Order Refrence From Sales Qutation in Sales order newOrder.SetPOReference(Util.GetValueOfString(from.GetDocumentNo())); // Added by Bharat on 31 Jan 2018 to set Inco Term from Quotation if (newOrder.Get_ColumnIndex("C_IncoTerm_ID") > 0) { newOrder.SetC_IncoTerm_ID(from.GetC_IncoTerm_ID()); } String sqlbp = "update c_project set c_bpartner_id=" + C_Bpartner_ID + " where ref_order_id=" + _C_Order_ID + ""; int value = DB.ExecuteQuery(sqlbp, null, Get_Trx()); bool OK = newOrder.Save(); if (!OK) { //return GetReterivedError( newOrder, "Could not create new Order"); throw new Exception("Could not create new Order"); } if (OK) { string sql = "select C_Project_id from c_project where c_order_id = " + from.GetC_Order_ID(); int C_Project_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())); if (C_Project_ID != 0) { VAdvantage.Model.X_C_Project project = new VAdvantage.Model.X_C_Project(GetCtx(), C_Project_ID, Get_Trx()); project.SetC_BPartner_ID(project.GetC_BPartnerSR_ID()); project.SetC_BPartnerSR_ID(0); if (!project.Save()) { log.SaveError("Error on " + project.Get_TableName(), ""); } } if (dt.GetDocBaseType() == "BOO") { from.SetC_Order_Blanket(newOrder.GetC_Order_ID()); } else { from.SetRef_Order_ID(newOrder.GetC_Order_ID()); } from.Save(); int bp = newOrder.GetC_BPartner_ID(); VAdvantage.Model.X_C_BPartner prosp = new VAdvantage.Model.X_C_BPartner(GetCtx(), bp, Get_Trx()); prosp.SetIsCustomer(true); prosp.SetIsProspect(false); if (!prosp.Save()) { log.SaveError("Error on " + prosp.Get_TableName(), ""); } } // if (_IsCloseDocument) { VAdvantage.Model.MOrder original = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx()); //Edited by Arpit Rai on 8th of Nov,2017 if (original.GetDocStatus() != "CO") //to check if document is already completed { original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Complete); original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Complete); original.Save(); } //Arpit original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Close); original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Close); original.Save(); } docNo = newOrder.GetDocumentNo(); } //+ ": " + newOrder.GetDocumentNo() return(Msg.GetMsg(GetCtx(), "OrderCreatedSuccessfully") + " - " + dt.GetName() + ": " + docNo); }
public string CompleteIt() { try { MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID()); String DocSubTypeSO = dt.GetDocSubTypeSO(); // Just prepare if (DOCACTION_Prepare.Equals(GetDocAction())) { SetProcessed(false); return(DocActionVariables.STATUS_INPROGRESS); } //if (!IsReturnTrx()) //{ // // Offers // if (MDocType.DOCSUBTYPESO_Proposal.Equals(DocSubTypeSO) // || MDocType.DOCSUBTYPESO_Quotation.Equals(DocSubTypeSO)) // { // // Binding // if (MDocType.DOCSUBTYPESO_Quotation.Equals(DocSubTypeSO)) // ReserveStock(dt, GetLines(true, "M_Product_ID")); // SetProcessed(true); // SetDocAction(DOCACTION_Close); // return DocActionVariables.STATUS_COMPLETED; // } // // Waiting Payment - until we have a payment // if (!_forceCreation // && MDocType.DOCSUBTYPESO_PrepayOrder.Equals(DocSubTypeSO) // && GetC_Payment_ID() == 0 && GetC_CashLine_ID() == 0) // { // SetProcessed(true); // return DocActionVariables.STATUS_WAITINGPAYMENT; // } // // Re-Check // if (!_justPrepared) // { // String status = PrepareIt(); // if (!DocActionVariables.STATUS_INPROGRESS.Equals(status)) // return status; // } //} // Re-Check if (!_justPrepared) { String status = PrepareIt(); if (!DocActionVariables.STATUS_INPROGRESS.Equals(status)) { return(status); } } // Implicit Approval if (!IsApproved()) { ApproveIt(); } //GetLines(true, null); log.Info(ToString()); StringBuilder Info = new StringBuilder(); /* nnayak - Bug 1720003 - We need to set the processed flag so the Tax Summary Line * does not get recreated in the afterSave procedure of the MOrderLine class */ //bool realTimePOS = false; //// Create SO Shipment - Force Shipment //MInOut shipment = null; //if (MDocType.DOCSUBTYPESO_OnCreditOrder.Equals(DocSubTypeSO) // (W)illCall(I)nvoice // || MDocType.DOCSUBTYPESO_WarehouseOrder.Equals(DocSubTypeSO) // (W)illCall(P)ickup // || MDocType.DOCSUBTYPESO_POSOrder.Equals(DocSubTypeSO) // (W)alkIn(R)eceipt // || MDocType.DOCSUBTYPESO_PrepayOrder.Equals(DocSubTypeSO)) //{ // if (!DELIVERYRULE_Force.Equals(GetDeliveryRule())) // SetDeliveryRule(DELIVERYRULE_Force); // // // shipment = CreateShipment(dt, realTimePOS ? null : GetDateOrdered()); // if (shipment == null) // return DocActionVariables.STATUS_INVALID; // Info.Append("@M_InOut_ID@: ").Append(shipment.GetDocumentNo()); // String msg = shipment.GetProcessMsg(); // if (msg != null && msg.Length > 0) // Info.Append(" (").Append(msg).Append(")"); //} // Create SO Invoice - Always invoice complete Order //if (MDocType.DOCSUBTYPESO_POSOrder.Equals(DocSubTypeSO) // || MDocType.DOCSUBTYPESO_OnCreditOrder.Equals(DocSubTypeSO) // || MDocType.DOCSUBTYPESO_PrepayOrder.Equals(DocSubTypeSO)) //{ // try // { // DateTime? tSet = realTimePOS ? null : GetDateOrdered(); // MInvoice invoice = CreateInvoice(dt, shipment, tSet); // if (invoice == null) // return DocActionVariables.STATUS_INVALID; // Info.Append(" - @C_Invoice_ID@: ").Append(invoice.GetDocumentNo()); // String msg = invoice.GetProcessMsg(); // if (msg != null && msg.Length > 0) // Info.Append(" (").Append(msg).Append(")"); // } // catch (NullReferenceException ex) // { // //ShowMessage.Error("Moder",null,"Completeit"); // } //} // Counter Documents //MOrder counter = CreateCounterDoc(); //if (counter != null) // Info.Append(" - @CounterDoc@: @Order@=").Append(counter.GetDocumentNo()); ////User Validation //String valid = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_AFTER_COMPLETE); //if (valid != null) //{ // if (Info.Length > 0) // Info.Append(" - "); // Info.Append(valid); // _processMsg = Info.ToString(); // return DocActionVariables.STATUS_INVALID; //} bool msg = CheckForPreviousCompeletedRecords(); if (!msg) { return(DocActionVariables.STATUS_INVALID); // return _processMsg; } SetProcessed(true); _processMsg = Info.ToString(); SetDocAction(DOCACTION_Close); } catch { //ShowMessage.Error("MOrder",null,"CompleteIt"); } return(DocActionVariables.STATUS_COMPLETED); }
/// <summary> /// Perform Process. /// </summary> /// <returns>Message (clear text)</returns> protected override String DoIt() { //log.Info("C_Order_ID=" + _C_Order_ID // + ", C_DocType_ID=" + _C_DocType_ID // + ", CloseDocument=" + _IsCloseDocument); //if (_C_Order_ID == 0) //{ // throw new ArgumentException("No Order"); //} //MDocType dt = MDocType.Get(GetCtx(), _C_DocType_ID); //if (dt.Get_ID() == 0) //{ // throw new ArgumentException("No DocType"); //} //if (_DateDoc == null) //{ // _DateDoc = DateTime.Now; // //Util.GetValueOfDateTime(new DateTime(CommonFunctions.CurrentTimeMillis())); //} //// //MOrder from = new MOrder(GetCtx(), _C_Order_ID, Get_Trx()); //MOrder newOrder = MOrder.CopyFrom(from, _DateDoc, // dt.GetC_DocType_ID(), false, true, null); // copy ASI //newOrder.SetC_DocTypeTarget_ID(_C_DocType_ID); //bool OK = newOrder.Save (); //if (!OK) //{ // throw new Exception("Could not create new Order"); //} //// //if (_IsCloseDocument) //{ // MOrder original = new MOrder(GetCtx(), _C_Order_ID, Get_Trx()); // original.SetDocAction(MOrder.DOCACTION_Complete); // original.ProcessIt(MOrder.DOCACTION_Complete); // original.Save(); // original.SetDocAction(MOrder.DOCACTION_Close); // original.ProcessIt(MOrder.DOCACTION_Close); // original.Save(); //} //// //return dt.GetName() + ": " + newOrder.GetDocumentNo(); log.Info("C_Order_ID=" + _C_Order_ID + ", C_DocType_ID=" + _C_DocType_ID + ", CloseDocument=" + _IsCloseDocument); if (_C_Order_ID == 0) { throw new ArgumentException("No Order"); } VAdvantage.Model.MDocType dt = VAdvantage.Model.MDocType.Get(GetCtx(), _C_DocType_ID); if (dt.Get_ID() == 0) { throw new ArgumentException("No DocType"); } if (_DateDoc == null) { _DateDoc = Util.GetValueOfDateTime(DateTime.Now); } // VAdvantage.Model.MOrder from = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx()); MOrder newOrder = MOrder.CopyFrom(from, _DateDoc, dt.GetC_DocType_ID(), false, true, null, true);//Pass optional parameter as True that we are going to create Order from Create Sales Order Process on Sales Quotation window---Neha newOrder.SetC_DocTypeTarget_ID(_C_DocType_ID); //Update New Order Refrence From Sales Qutation in Sales order newOrder.SetPOReference(Util.GetValueOfString(from.GetDocumentNo())); int C_Bpartner_ID = newOrder.GetC_BPartner_ID(); newOrder.Set_Value("IsSalesQuotation", false); // Added by Bharat on 31 Jan 2018 to set Inco Term from Quotation if (newOrder.Get_ColumnIndex("C_IncoTerm_ID") > 0) { newOrder.SetC_IncoTerm_ID(from.GetC_IncoTerm_ID()); } String sqlbp = "update c_project set c_bpartner_id=" + C_Bpartner_ID + " where ref_order_id=" + _C_Order_ID + ""; int value = DB.ExecuteQuery(sqlbp, null, Get_Trx()); bool OK = newOrder.Save(); if (!OK) { throw new Exception("Could not create new Order"); } if (OK) { string sql = "select C_Project_id from c_project where c_order_id = " + from.GetC_Order_ID(); int C_Project_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())); if (C_Project_ID != 0) { VAdvantage.Model.X_C_Project project = new VAdvantage.Model.X_C_Project(GetCtx(), C_Project_ID, Get_Trx()); project.SetC_BPartner_ID(project.GetC_BPartnerSR_ID()); project.SetC_BPartnerSR_ID(0); if (!project.Save()) { } } from.SetRef_Order_ID(newOrder.GetC_Order_ID()); from.Save(); int bp = newOrder.GetC_BPartner_ID(); VAdvantage.Model.X_C_BPartner prosp = new VAdvantage.Model.X_C_BPartner(GetCtx(), bp, Get_Trx()); prosp.SetIsCustomer(true); prosp.SetIsProspect(false); prosp.Save(); } // if (_IsCloseDocument) { VAdvantage.Model.MOrder original = new VAdvantage.Model.MOrder(GetCtx(), _C_Order_ID, Get_Trx()); //Edited by Arpit Rai on 8th of Nov,2017 if (original.GetDocStatus() != "CO") //to check if document is already completed { original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Complete); original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Complete); original.Save(); } //Arpit original.SetDocAction(VAdvantage.Model.MOrder.DOCACTION_Close); original.ProcessIt(VAdvantage.Model.MOrder.DOCACTION_Close); original.Save(); } // return(Msg.GetMsg(GetCtx(), "OrderCreatedSuccessfully") + " - " + dt.GetName() + ": " + newOrder.GetDocumentNo()); }
public string PrepareIt() { log.Info(ToString()); _processMsg = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_BEFORE_PREPARE); if (_processMsg != null) { return(DocActionVariables.STATUS_INVALID); } MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID()); //SetIsReturnTrx(dt.IsReturnTrx()); //SetIsSOTrx(dt.IsSOTrx()); // Std Period open? if (!MPeriod.IsOpen(GetCtx(), GetDateAcct(), dt.GetDocBaseType())) { _processMsg = "@PeriodClosed@"; return(DocActionVariables.STATUS_INVALID); } // is Non Business Day? if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateAcct())) { _processMsg = Common.Common.NONBUSINESSDAY; return(DocActionVariables.STATUS_INVALID); } // Lines MProfitLossLines[] lines = GetLines(true); if (lines.Length == 0) { _processMsg = "@NoLines@"; return(DocActionVariables.STATUS_INVALID); } //// Convert DocType to Target //if (GetC_DocType_ID() != GetC_DocTypeTarget_ID()) //{ // // Cannot change Std to anything else if different warehouses // if (GetC_DocType_ID() != 0) // { // MDocType dtOld = MDocType.Get(GetCtx(), GetC_DocType_ID()); // if (MDocType.DOCSUBTYPESO_StandardOrder.Equals(dtOld.GetDocSubTypeSO()) // From SO // && !MDocType.DOCSUBTYPESO_StandardOrder.Equals(dt.GetDocSubTypeSO())) // To !SO // { // for (int i = 0; i < lines.Length; i++) // { // if (lines[i].GetM_Warehouse_ID() != GetM_Warehouse_ID()) // { // log.Warning("different Warehouse " + lines[i]); // _processMsg = "@CannotChangeDocType@"; // return DocActionVariables.STATUS_INVALID; // } // } // } // } // // New or in Progress/Invalid // if (DOCSTATUS_Drafted.Equals(GetDocStatus()) // || DOCSTATUS_InProgress.Equals(GetDocStatus()) // || DOCSTATUS_Invalid.Equals(GetDocStatus()) // || GetC_DocType_ID() == 0) // { // SetC_DocType_ID(GetC_DocTypeTarget_ID()); // } // else // convert only if offer // { // if (dt.IsOffer()) // SetC_DocType_ID(GetC_DocTypeTarget_ID()); // else // { // _processMsg = "@CannotChangeDocType@"; // return DocActionVariables.STATUS_INVALID; // } // } //} // convert DocType // Mandatory Product Attribute Set Instance //String mandatoryType = "='Y'"; // IN ('Y','S') //String sql = "SELECT COUNT(*) " // + "FROM C_OrderLine ol" // + " INNER JOIN M_Product p ON (ol.M_Product_ID=p.M_Product_ID)" // + " INNER JOIN M_AttributeSet pas ON (p.M_AttributeSet_ID=pas.M_AttributeSet_ID) " // + "WHERE pas.MandatoryType" + mandatoryType // + " AND ol.M_AttributeSetInstance_ID IS NULL" // + " AND ol.C_Order_ID=" + GetC_Order_ID(); //int no = DataBase.DB.GetSQLValue(Get_TrxName(), sql); //if (no != 0) //{ // _processMsg = "@LinesWithoutProductAttribute@ (" + no + ")"; // return DocActionVariables.STATUS_INVALID; //} //// Lines //if (ExplodeBOM()) // lines = GetLines(true, "M_Product_ID"); //if (!ReserveStock(dt, lines)) //{ // _processMsg = "Cannot reserve Stock"; // return DocActionVariables.STATUS_INVALID; //} //if (!CalculateTaxTotal()) //{ // _processMsg = "Error calculating tax"; // return DocActionVariables.STATUS_INVALID; //} //// Credit Check //if (IsSOTrx() && !IsReturnTrx()) //{ // MBPartner bp = MBPartner.Get(GetCtx(), GetC_BPartner_ID()); // if (MBPartner.SOCREDITSTATUS_CreditStop.Equals(bp.GetSOCreditStatus())) // { // _processMsg = "@BPartnerCreditStop@ - @TotalOpenBalance@=" // + bp.GetTotalOpenBalance() // + ", @SO_CreditLimit@=" + bp.GetSO_CreditLimit(); // return DocActionVariables.STATUS_INVALID; // } // if (MBPartner.SOCREDITSTATUS_CreditHold.Equals(bp.GetSOCreditStatus())) // { // _processMsg = "@BPartnerCreditHold@ - @TotalOpenBalance@=" // + bp.GetTotalOpenBalance() // + ", @SO_CreditLimit@=" + bp.GetSO_CreditLimit(); // return DocActionVariables.STATUS_INVALID; // } // Decimal grandTotal = MConversionRate.ConvertBase(GetCtx(), // GetGrandTotal(), GetC_Currency_ID(), GetDateOrdered(), // GetC_ConversionType_ID(), GetAD_Client_ID(), GetAD_Org_ID()); // if (MBPartner.SOCREDITSTATUS_CreditHold.Equals(bp.GetSOCreditStatus(grandTotal))) // { // _processMsg = "@BPartnerOverOCreditHold@ - @TotalOpenBalance@=" // + bp.GetTotalOpenBalance() + ", @GrandTotal@=" + grandTotal // + ", @SO_CreditLimit@=" + bp.GetSO_CreditLimit(); // return DocActionVariables.STATUS_INVALID; // } //} _justPrepared = true; // dont uncomment //if (!DOCACTION_Complete.Equals(getDocAction())) don't set for just prepare // setDocAction(DOCACTION_Complete); return(DocActionVariables.STATUS_INPROGRESS); }
/** * Complete Document * @return new status (Complete, In Progress, Invalid, Waiting ..) */ public String CompleteIt() { // Re-Check if (!_justPrepared) { String status = PrepareIt(); if (!DocActionVariables.STATUS_INPROGRESS.Equals(status)) { return(status); } } // Implicit Approval if (!IsApproved()) { ApproveIt(); } log.Info(ToString()); // MInOut inout = new MInOut(GetCtx(), GetM_InOut_ID(), Get_TrxName()); MInOutLineConfirm[] lines = GetLines(false); // Check if we need to split Shipment if (IsInDispute()) { MDocType dt = MDocType.Get(GetCtx(), inout.GetC_DocType_ID()); if (dt.IsSplitWhenDifference()) { if (dt.GetC_DocTypeDifference_ID() == 0) { _processMsg = "No Split Document Type defined for: " + dt.GetName(); return(DocActionVariables.STATUS_INVALID); } SplitInOut(inout, dt.GetC_DocTypeDifference_ID(), lines); _lines = null; } } // All lines for (int i = 0; i < lines.Length; i++) { MInOutLineConfirm confirmLine = lines[i]; confirmLine.Set_TrxName(Get_TrxName()); if (!confirmLine.ProcessLine(inout.IsSOTrx(), GetConfirmType())) { _processMsg = "ShipLine not saved - " + confirmLine; return(DocActionVariables.STATUS_INVALID); } if (confirmLine.IsFullyConfirmed()) { confirmLine.SetProcessed(true); confirmLine.Save(Get_TrxName()); } else { if (CreateDifferenceDoc(inout, confirmLine)) { confirmLine.SetProcessed(true); confirmLine.Save(Get_TrxName()); } else { log.Log(Level.SEVERE, "Scrapped=" + confirmLine.GetScrappedQty() + " - Difference=" + confirmLine.GetDifferenceQty()); return(DocActionVariables.STATUS_INVALID); } } } // for all lines if (_creditMemo != null) { _processMsg += " @C_Invoice_ID@=" + _creditMemo.GetDocumentNo(); } if (_inventory != null) { _processMsg += " @M_Inventory_ID@=" + _inventory.GetDocumentNo(); } // User Validation String valid = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_AFTER_COMPLETE); if (valid != null) { _processMsg = valid; return(DocActionVariables.STATUS_INVALID); } SetProcessed(true); SetDocAction(DOCACTION_Close); return(DocActionVariables.STATUS_COMPLETED); }