private void InvoiceRDraft() { SAPbouiCOM.Form lObjFormDraft = null; int lIntRetCode = 0; int lIntKeyD = 0; int lIntCounter = 0; int lIntPrevKey = 0; bool lBoolDraft = false; string lStrArticle = mObjRejectedDAO.GetArticleToInvoice(); lObjDraftInvoice = (SAPbobsCOM.Documents)DIApplication.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts); var lVarRejectedToInv = from p in lListRejectedToInvoice group p by p.Client into gr select gr; try { foreach (var lVarClient in lVarRejectedToInv) { foreach (var item in lVarClient) { lObjErrorListDTO = new DTO.ErrorListDTO(); lStrReference = lStrMainRWhs + "_" + item.Inspection; if (!CheckThreeDays(lIntCounter)) { if (!HasInvoice(lStrReference, item.DistNumb)) { if (SetCosts(item.Inspection, lIntCounter) != -1) { lIntKeyD = mObjRejectedDAO.GetDraftKey(lStrReference, lStrArticle); if (lIntKeyD > 0 && lIntKeyD != lIntPrevKey) { lObjDraftInvoice.GetByKey(lIntKeyD); lObjDraftInvoice.Remove(); lIntKeyD = 0; } if (lIntKeyD == 0) { lObjDraftInvoice.DocObjectCodeEx = "13"; lObjDraftInvoice.CardCode = item.Client; lObjDraftInvoice.Lines.FreeText = lStrReference; lObjDraftInvoice.Lines.ItemCode = lStrArticle; lObjDraftInvoice.Lines.TaxCode = mObjRejectedDAO.GetTaxCode(lStrArticle); lObjDraftInvoice.Lines.Quantity = item.QuantityConcept; lObjDraftInvoice.Lines.LineTotal = item.Price; lObjDraftInvoice.Lines.Add(); lBoolDraft = true; lObjErrorListDTO.Option = "Correct"; lObjErrorListDTO.Inspection = lListRejectedToInvoice[lIntCounter].Inspection; lObjlstErrorDTO.Add(lObjErrorListDTO); } //else //{ // lObjErrorListDTO.Option = "HasDraft"; // lObjErrorListDTO.Inspection = lListRejectedToInvoice[lIntCounter].Inspection; // lObjlstErrorDTO.Add(lObjErrorListDTO); // if (lObjChckBox.Checked) // { // lIntKeyD = mObjRejectedDAO.GetDraftKey(lStrReference, lStrArticle); // if (lIntKeyD > 0 && lIntKeyD != lIntPrevKey) // { // lObjDraftInvoice.GetByKey(lIntKeyD); // if (lObjDraftInvoice.DocDate < lObjDatetime) // { // lObjDraftInvoice.Remove(); // } // else // { // lObjFormDraft = Application.SBO_Application.OpenForm((SAPbouiCOM.BoFormObjectEnum)112, "", lIntKeyD.ToString()); // lIntPrevKey = lIntKeyD; // } // } // } //} } else { lObjErrorListDTO.Option = "InvalidDate"; lObjErrorListDTO.Inspection = lListRejectedToInvoice[lIntCounter].Inspection.ToString(); lObjlstErrorDTO.Add(lObjErrorListDTO); } } else { lObjErrorListDTO.Option = "WithInvoice"; lObjErrorListDTO.Inspection = lListRejectedToInvoice[lIntCounter].Inspection.ToString(); lObjlstErrorDTO.Add(lObjErrorListDTO); } } else { lObjErrorListDTO.Option = "OnTime"; lObjErrorListDTO.Inspection = lListRejectedToInvoice[lIntCounter].Inspection.ToString(); lObjlstErrorDTO.Add(lObjErrorListDTO); } lIntCounter++; } if (lBoolDraft) { lIntRetCode = lObjDraftInvoice.Add(); if (lIntRetCode != 0) { string lStrError = DIApplication.Company.GetLastErrorDescription(); Application.SBO_Application.StatusBar.SetText(lStrError , SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error); } lIntKeyD = mObjRejectedDAO.GetDraftKey(lStrReference, lStrArticle); if (lObjChckBox.Checked) { if (lIntKeyD > 0 && lIntKeyD != lIntPrevKey) { lObjFormDraft = Application.SBO_Application.OpenForm((SAPbouiCOM.BoFormObjectEnum) 112, "", lIntKeyD.ToString()); lIntPrevKey = lIntKeyD; } } } } } catch (Exception lObjException) { throw new DAOException(lObjException.Message, lObjException); } finally { MemoryUtility.ReleaseComObject(lObjDraftInvoice); } }