Ejemplo n.º 1
0
        public async Task GetDocFromStore(DateTime period)
        {
            BilingTypes = await BilingType.GetBilinTypesAsync();

            List <ResultPaymentMatrix> matrices = await PaymentMatrix.GetPaymentMatrixAsync(period);

            if (matrices != null && matrices.Count > 0)
            {
                // DELETE NV.
                DeleteNV();
                // INSERT TRIGGER.
                DteInfoRef.InsertTriggerRefCen(Conn);
                List <ResultInstruction> i = await GetInstructions(matrices);

                if (i.Count > 0)
                {
                    try
                    {
                        DetalleList.AddRange(await GetCreditor(i));
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
                else
                {
                    // DetalleList = null;
                }
            }
        }
Ejemplo n.º 2
0
        public async Task GetDocFromStore(DateTime period)
        {
            // INFO
            PgModel.StopWatch.Start();
            BilingTypes = await BilingType.GetBilinTypesAsync();

            string         nameFile = @"C:\Centralizador\Inbox\" + period.Year + @"\" + period.Month;
            string         p        = $"{period.Year}-{string.Format("{0:00}", period.Month)}";
            List <Detalle> lista33  = await ServiceDetalle.GetLibroAsync("Debtor", UserParticipant, "33", p, TokenSii, Progress);

            List <Detalle> lista34 = await ServiceDetalle.GetLibroAsync("Debtor", UserParticipant, "34", p, TokenSii, Progress);

            List <Detalle> listaTotal = new List <Detalle>();

            if (lista33 != null)
            {
                foreach (var item in lista33)
                {
                    item.Tipo = "33";
                    listaTotal.Add(item);
                }
            }
            if (lista34 != null)
            {
                foreach (var item in lista34)
                {
                    item.Tipo = "34";
                    listaTotal.Add(item);
                }
            }
            if (listaTotal != null && listaTotal.Count > 0)
            {
                try
                {
                    DetalleList = await GetDebtor(listaTotal, nameFile);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 3
0
        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);
        }