public async Task InsertNotaVenta(List <Detalle> detalles) { StringLogging.Clear(); // GET VALUES LIST FROM CSV. FileSii.ReadFileSii(); FoliosNv = await InsertNv(detalles); if (FoliosNv != null && FoliosNv.Count > 0) { string nameFile = $"{UserParticipant.Name}_InsertNv_{DateTime.Now:dd-MM-yyyy-HH-mm-ss}"; StringLogging.AppendLine(""); StringLogging.AppendLine($"Summary: From {FoliosNv.Min()} To-{FoliosNv.Max()}"); SaveLogging(@"C:\Centralizador\Log\", nameFile); } else if (StringLogging.Length > 0) { string nameFile = $"{UserParticipant.Name}_InsertNv_{DateTime.Now:dd-MM-yyyy-HH-mm-ss}"; StringLogging.AppendLine(""); SaveLogging(@"C:\Centralizador\Log\", nameFile); } }
public async Task <List <int> > InsertNv(List <Detalle> detalles) { BilingTypes = await BilingType.GetBilinTypesAsync(); int c = 0; float porcent = 0; TextInfo ti = CultureInfo.CurrentCulture.TextInfo; int resultInsertNV; int lastF = 0; List <int> folios = new List <int>(); foreach (Detalle item in detalles) { AuxCsv a = FileSii.GetAuxCvsFromFile(item); // INFORMATION UPDATE FROM CSV FILE. if (a != null) { string name = ti.ToTitleCase(a.Name.ToLower()); item.Instruction.ParticipantDebtor.BusinessName = name; item.Instruction.ParticipantDebtor.DteReceptionEmail = a.Email; item.Instruction.ParticipantDebtor.Name = item.Instruction.ParticipantDebtor.Name.ToUpper(); } else { StringLogging.AppendLine($"{item.Instruction.Id}\tUpdate email\t\tError in CSV file."); continue; } Auxiliar aux = await Auxiliar.GetAuxiliarAsync(item.Instruction, Conn); Comuna comunaobj; if (aux == null) // INSERT NEW AUX. { comunaobj = await Comuna.GetComunaFromInput(item, Conn, true); aux = await Auxiliar.InsertAuxiliarAsync(item.Instruction, Conn, comunaobj); if (aux != null) { StringLogging.AppendLine($"{item.Instruction.Id}\tAuxiliar Insert:\tOk: {item.Instruction.ParticipantDebtor.Rut} / {aux.DirAux} / {aux.ComAux}"); } else { StringLogging.AppendLine($"{item.Instruction.Id}\tAuxiliar Error:\t {item.Instruction.ParticipantDebtor.Rut}"); } } else // UPDATE ALL AUX FROM LIST. { if (aux.ComAux == null) { comunaobj = await Comuna.GetComunaFromInput(item, Conn, false); } else { comunaobj = new Comuna { ComCod = aux.ComAux }; } if (await aux.UpdateAuxiliarAsync(item.Instruction, Conn, comunaobj) == 0) { StringLogging.AppendLine($"{item.Instruction.Id}\tAuxiliar Update:\tError Sql: {item.Instruction.ParticipantDebtor.Rut}"); continue; } } // INSERT THE NV. lastF = await NotaVenta.GetLastNv(Conn); string prod = BilingTypes.FirstOrDefault(x => x.Id == item.Instruction.PaymentMatrix.BillingWindow.BillingType).DescriptionPrefix; resultInsertNV = await NotaVenta.InsertNvAsync(item.Instruction, lastF, prod, Conn); if (resultInsertNV == 0) { StringLogging.AppendLine($"{item.Instruction.Id}\tInsert NV:\tError Sql"); } else if (resultInsertNV == 1) // SUCCESS INSERT. { if (item.Instruction.ParticipantNew == null) { StringLogging.AppendLine($"{item.Nro}-{item.Instruction.Id}\tInsert NV:\tF°: {lastF}"); } else { StringLogging.AppendLine($"{item.Instruction.Id}\tInsert NV:\tF°: {lastF} *Change RUT {item.Instruction.ParticipantDebtor.Rut} by {item.Instruction.ParticipantNew.Rut}"); } folios.Add(lastF); } c++; porcent = (float)(100 * c) / detalles.Count; await ReportProgress(porcent, $"Inserting NV, wait please... ({c}/{detalles.Count}) F°: {lastF})"); } return(folios); }