private string AttatchFile(string pStrFile) { int lIntAttachement = 0; string lStrAttach = string.Empty; string lStrAttachPath = mObjPurchaseServiceFactory.GetPurchaseService().GetAttachPath(); if (!string.IsNullOrEmpty(pStrFile)) { if (!Directory.Exists(lStrAttachPath)) { if (SAPbouiCOM.Framework.Application.SBO_Application.MessageBox(string.Format("Carpeta {0} \n no accesible es posible que no pueda adjuntar el xml ¿Desea continuar?", lStrAttachPath), 2, "Si", "No", "") == 2) { return(""); } } } AttachmentDI lObjAttachmentDI = new AttachmentDI(); lIntAttachement = lObjAttachmentDI.AttachFile(pStrFile); if (lIntAttachement > 0) { lStrAttach = lStrAttachPath + System.IO.Path.GetFileName(pStrFile); } else { LogService.WriteError("InvoiceDI (AttachDocument) " + DIApplication.Company.GetLastErrorDescription()); UIApplication.ShowError(string.Format("InvoiceDI (AttachDocument) : {0}", DIApplication.Company.GetLastErrorDescription())); } return(lStrAttach); }
public IList <string> CreateDocument(List <PurchaseNote> pLstPurchaseNotes, Vouchers pObjVoucher, TypeEnum.Type pNoteType) { IList <string> lLstResult = new List <string>(); try { string lStrDocEntry = string.Empty; SAPbobsCOM.JournalEntries lObjJournalEntryes = (SAPbobsCOM.JournalEntries)DIApplication.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalEntries); //SAPbobsCOM.BoObjectTypes.oInvoices); lObjJournalEntryes.TransactionCode = "S/CF"; lObjJournalEntryes.Memo = "CND" + " " + pObjVoucher.Area; lObjJournalEntryes.ReferenceDate = pObjVoucher.Date; if (pNoteType == TypeEnum.Type.Refund) { lObjJournalEntryes.Reference = pObjVoucher.Folio; } else { lObjJournalEntryes.Reference = pObjVoucher.CodeMov; } var pLstPurchaseNotesAffectable = pLstPurchaseNotes.GroupBy(x => x.Affectable).Select(x => new PurchaseNote() { Affectable = x.First().Affectable, Area = x.First().Area, CostingCode = x.First().CostingCode, Aux = x.First().AuxAfectable, AF = x.First().AF, CodeMov = x.First().CodeMov, CodeVoucher = x.First().CodeVoucher, Amount = x.Sum(y => y.Amount) //x.Select(y=> y.Amount).Sum().ToString(), }).ToList(); string lStrAttachPath = mObjPurchaseServiceFactory.GetPurchaseService().GetAttachPath(); foreach (PurchaseNote lObjNotes in pLstPurchaseNotes) { int lIntAttachement = 0; string lStrAttach = string.Empty; if (!string.IsNullOrEmpty(lObjNotes.File)) { AttachmentDI lObjAttachmentDI = new AttachmentDI(); lIntAttachement = lObjAttachmentDI.AttachFile(lObjNotes.File); if (lIntAttachement > 0) { lStrAttach = lStrAttachPath + System.IO.Path.GetFileName(lObjNotes.File); } else { lStrAttach = lObjNotes.File; } } lObjJournalEntryes.Lines.Credit = 0; // Convert.ToDouble(lObjMovement.Credit); lObjJournalEntryes.Lines.Debit = lObjNotes.Amount; lObjJournalEntryes.Lines.AccountCode = lObjNotes.Account; lObjJournalEntryes.Lines.ProjectCode = lObjNotes.Project; lObjJournalEntryes.Lines.CostingCode = lObjNotes.Area; lObjJournalEntryes.Lines.CostingCode2 = lObjNotes.AF; lObjJournalEntryes.Lines.CostingCode3 = lObjNotes.AGL; lObjJournalEntryes.Lines.CostingCode4 = lObjNotes.Line; lObjJournalEntryes.Lines.Reference2 = lObjNotes.Folio; lObjJournalEntryes.Lines.LineMemo = lObjNotes.Provider; lObjJournalEntryes.Lines.UserFields.Fields.Item("U_GLO_Coments").Value = lObjNotes.Coments; lObjJournalEntryes.Lines.UserFields.Fields.Item("U_GLO_File").Value = lStrAttach; lObjJournalEntryes.Lines.UserFields.Fields.Item("U_GLO_TypeAux").Value = "2"; lObjJournalEntryes.Lines.UserFields.Fields.Item("U_GLO_Auxiliar").Value = lObjNotes.Aux; lObjJournalEntryes.Lines.UserFields.Fields.Item("U_GLO_CodeMov").Value = string.IsNullOrEmpty(lObjNotes.CodeMov) ? pObjVoucher.Folio : lObjNotes.CodeMov; if (!string.IsNullOrEmpty(lObjNotes.Aux)) { lObjJournalEntryes.Lines.UserFields.Fields.Item("U_GLO_TypeAux").Value = "2"; } lObjJournalEntryes.Lines.Add(); } foreach (PurchaseNote lObjAffectable in pLstPurchaseNotesAffectable) { lObjJournalEntryes.Lines.AccountCode = lObjAffectable.Affectable; lObjJournalEntryes.Lines.Credit = lObjAffectable.Amount; lObjJournalEntryes.Lines.Debit = 0; lObjJournalEntryes.Lines.CostingCode = lObjAffectable.CostingCode; lObjJournalEntryes.Lines.CostingCode2 = lObjAffectable.AF; lObjJournalEntryes.Lines.UserFields.Fields.Item("U_GLO_TypeAux").Value = "2"; lObjJournalEntryes.Lines.UserFields.Fields.Item("U_GLO_Auxiliar").Value = lObjAffectable.Aux; lObjJournalEntryes.Lines.UserFields.Fields.Item("U_GLO_CodeMov").Value = pNoteType == TypeEnum.Type.Refund ? pObjVoucher.Folio : lObjAffectable.CodeMov; /*string.IsNullOrEmpty(lObjAffectable.CodeMov) ? * lObjAffectable.CodeVoucher * :lObjAffectable.CodeMov;*///lObjAffectable.CodeVoucher; } if (lObjJournalEntryes.Add() != 0) { lLstResult.Add(string.Format("Mensaje: {0} ", DIApplication.Company.GetLastErrorDescription())); LogService.WriteError("PolicyDI (CreateDocument) Código de comprobante:" + pObjVoucher.RowCode + " Mensaje:" + DIApplication.Company.GetLastErrorDescription()); } else { LogService.WriteSuccess("Asiento creado correctamente: Código de comprobante:" + pObjVoucher.RowCode); // AddVoucherDetail(pLstPurchaseNotes); } // var ss = pLstPurchaseNotes.GroupBy(x => x.Account, x => x.AF, x => x.Area); } catch (Exception ex) { LogService.WriteError("PolicyDI (CreateDocument) Código de comprobante:" + pObjVoucher.RowCode + " Mensaje:" + ex.Message); LogService.WriteError(ex); lLstResult.Add(ex.Message); // throw new Exception(ex.Message); } return(lLstResult); }