Пример #1
0
        async public Task Insert(Invoice entity)
        {
            try
            {
                IBatchProducer batch  = _serviceLayerConnector.CreateBatch();
                string         record = toJson(entity);
                batch.Post(HttpMethod.Post, "/Drafts", record);
                ServiceLayerResponse response = await _serviceLayerConnector.Post("Drafts", record, true, true);

                var resp1 = response.success;
                if (!response.success)
                {
                    var    idEntidade = entity.RecId;
                    var    cad        = toJsonError();
                    string query      = Global.BuildQuery($"U_VSITINVOICE('{idEntidade}')");
                    response = await _serviceLayerConnector.Patch(query, cad, true);
                }

                if (resp1)
                {
                    Invoice savedInvoice = JsonConvert.DeserializeObject <Invoice>(response.data);
                    var     idInvoice    = entity.RecId;
                    var     cad          = toJsonSucess(savedInvoice.DocEntry.Value, entity.FRT_VAL, entity.TRN_FAT);
                    string  query        = Global.BuildQuery($"U_VSITINVOICE('{idInvoice}')");
                    response = await _serviceLayerConnector.Patch(query, cad, true);
                }
            }
            catch (Exception e)
            {
            }
        }
Пример #2
0
        async public Task Delete(List <Criteria> criterias)
        {
            List <CfopToUsageMap> entities = await this.List(criterias, 0, 0);

            IBatchProducer batch = _serviceLayerConnector.CreateBatch();

            entities.ForEach(e =>
            {
                batch.Post(HttpMethod.Delete, $"/{SL_TABLE_NAME}('{e.RecId}')", "");
            });

            ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);

            if (!response.success)
            {
                string message = $"Erro ao excluir registros de '{entities[0].EntityName}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
            else if (response.internalResponses.Count(m => m.success == false) != 0)
            {
                var    error   = response.internalResponses[response.internalResponses.Count() - 1];
                string message = $"Erro ao excluir registros de '{entities[0].EntityName}': {error.errorCode}-{error.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
        }
Пример #3
0
        async public Task Insert(AccountIncomingInvoice entity)
        {
            string json = toJson(entity);

            ServiceLayerResponse response = await _serviceLayerConnector.Post($"{SL_SERVICE_NAME}", json);

            if (!response.success)
            {
                string message = $"{entity.EntityName}: Erro ao incluir {entity.NotaFiscal}-{entity.Parcela}, {response.errorCode} {response.errorMessage}";
                throw new OperationCanceledException(message);
            }
        }
Пример #4
0
        async public Task Insert(SalesInvoice entity)
        {
            string record = await toJson(entity);

            ServiceLayerResponse response = await _serviceLayerConnector.Post(SL_TABLE_NAME, record);

            if (!response.success)
            {
                string message = $"Erro ao enviar transação de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                throw new ApplicationException(message);
            }
        }
Пример #5
0
        async public Task Insert(JournalEntry entity)
        {
            IBatchProducer batch  = _serviceLayerConnector.CreateBatch();
            string         record = toJson(entity);

            batch.Post(HttpMethod.Post, "/JournalEntries", record);
            ServiceLayerResponse response = await _serviceLayerConnector.Post("JournalEntries", record, true, true);

            var resp1 = response.success;

            if (!response.success)
            {
                var    idEntidade = entity.RecId;
                var    cad        = toJsonError();
                string query      = Global.BuildQuery($"U_VSITENTIDADE('{idEntidade}')");
                response = await _serviceLayerConnector.Patch(query, cad, true);
            }

            if (resp1)
            {
                //Invoice savedInvoice = JsonConvert.DeserializeObject<JournalEntry>(response.data);
                var    idInvoice = entity.RecId;
                var    cad       = toJsonSucess();
                string query     = Global.BuildQuery($"U_VSITINVOICE('{idInvoice}')");
                response = await _serviceLayerConnector.Patch(query, cad, true);
            }
        }
Пример #6
0
        async public Task Insert(BusinessPartners entity)
        {
            try
            {
                var  Cards   = listCardCodes(entity.NATUREZA, entity.CODIGO);
                bool sucesso = true;

                foreach (var card in Cards)
                {
                    IBatchProducer batch = _serviceLayerConnector.CreateBatch();
                    entity.CardCode = card.CardName;
                    entity.CardType = card.CardType;
                    string record = toJson(entity);
                    batch.Post(HttpMethod.Post, "/BusinessPartners", record);
                    ServiceLayerResponse response = await _serviceLayerConnector.Post("BusinessPartners", record);

                    //códigos de erro para se o produto ja existe
                    if (!response.success)
                    {
                        sucesso = false;
                    }
                }

                if (sucesso)
                {
                    var    idEntidade = entity.RecId;
                    var    cad        = toJsonEntidades();
                    string query      = Global.BuildQuery($"U_VSITENTIDADE('{idEntidade}')");
                    var    response   = await _serviceLayerConnector.Patch(query, cad, true);
                }
                else
                {
                    var    idEntidade = entity.RecId;
                    var    cad        = toJsonError();
                    string query      = Global.BuildQuery($"U_VSITENTIDADE('{idEntidade}')");
                    var    response   = await _serviceLayerConnector.Patch(query, cad, true);
                }
            }
            catch (Exception e)
            {
            }
        }
Пример #7
0
        async public Task Insert(POSInvoicePayment entity)
        {
            ServiceLayerResponse response = await _serviceLayerConnector.Post(SL_TABLE_NAME, JsonConvert.SerializeObject(entity));

            if (!response.success)
            {
                string message = $"Erro ao enviar transação de '{entity.CardCode}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
        }
Пример #8
0
        async public Task Insert(ProductTree entity)
        {
            IBatchProducer batch = _serviceLayerConnector.CreateBatch();

            batch = _serviceLayerConnector.CreateBatch();
            string record = toJsonComponete(entity);

            batch.Post(HttpMethod.Post, "/ProductTrees", record);

            ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);

            if (!response.success)
            {
                string message = $"Erro ao enviar transação de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
            else
            {
                ProductTreeIntegrationStatus status = ProductTreeIntegrationStatus.Processed;

                if (response.internalResponses.Where(x => x.errorCode == "-2035").ToList().Count == 0)
                {
                    if (response.internalResponses.Count(m => !m.success) != 0)
                    {
                        status = ProductTreeIntegrationStatus.Error;
                    }
                }


                var prod = toJsonComponent(status);
                foreach (var item in entity.productTrees_Lines)
                {
                    string query          = Global.BuildQuery($"U_VSITPRODUCT_COMP('{item.RecId}')");
                    var    responseStatus = await _serviceLayerConnector.Patch(query, prod, true);

                    if (!responseStatus.success)
                    {
                        string message = $"Erro ao atualizar status de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                        Console.WriteLine(message);
                        throw new ApplicationException(message);
                    }
                }
            }
        }
Пример #9
0
        async public Task Insert(Items entity)
        {
            IBatchProducer batch = _serviceLayerConnector.CreateBatch();

            batch = _serviceLayerConnector.CreateBatch();
            string record = toJson(entity);

            batch.Post(HttpMethod.Post, "/Items", record);

            foreach (var i in entity.ItemBarCodes.Where(m => m.BarCode != entity.BarCode))
            {
                record = toJsonBarCode(i);
                batch.Post(HttpMethod.Post, "/BarCodes", record);
            }

            ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);

            if (!response.success)
            {
                string message = $"Erro ao enviar transação de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
            else
            {
                ProductIntegrationStatus status = ProductIntegrationStatus.Processed;

                if (response.internalResponses.Count(m => !m.success) != 0)
                {
                    status = ProductIntegrationStatus.Error;
                }

                var    prod           = toJsonProduct(status);
                string query          = Global.BuildQuery($"U_VSITPRODUCT('{entity.RecId}')");
                var    responseStatus = await _serviceLayerConnector.Patch(query, prod, true);

                if (!responseStatus.success)
                {
                    string message = $"Erro ao atualizar status de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                    Console.WriteLine(message);
                    throw new ApplicationException(message);
                }
            }
        }
Пример #10
0
        async public Task Insert(VSITVENC entity)
        {
            IBatchProducer batch = _serviceLayerConnector.CreateBatch();

            entity.status = Data.Model.Integration.VSITVENC.VSITVENCIntegrationStatus.Importing;
            string record = toJson(entity);

            batch.Post(HttpMethod.Post, "/U_VSITINVOICEVENC", record);

            ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);

            //
            // Erro no protocolo http ou na estrutura do arquivo
            //
            if (!response.success)
            {
                string message = $"Erro ao enviar transação de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
        }
Пример #11
0
        async public Task Insert(VSITENTIDADE entity)
        {
            //verifica se ja tem
            try
            {
                IBatchProducer batch = _serviceLayerConnector.CreateBatch();
                entity.cod_x25 = parseCountry(entity.cod_x25);
                entity.status  = Data.Model.Integration.VSITENTIDADE.VSITENTIDADEIntegrationStatus.Importing;
                string record = toJson(entity);

                batch.Post(HttpMethod.Post, "/U_VSITENTIDADE", record);
                ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);

                if (!response.success)
                {
                    string message = $"Erro ao enviar transação de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                    Console.WriteLine(message);
                    throw new ApplicationException(message);
                }
            }
            catch (Exception e)
            {
            }
        }
Пример #12
0
        async public Task Insert(ProductComponent entity)
        {
            IBatchProducer batch = _serviceLayerConnector.CreateBatch();

            // entity.status = Data.Model.Integration.Product.ProductIntegrationStatus.Importing;
            string record = toJson(entity);

            batch.Post(HttpMethod.Post, "/U_VSITPRODUCT_COMP", record);

            ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);

            //
            // Erro no protocolo http ou na estrutura do arquivo
            //
            if (!response.success)
            {
                string message = $"Erro ao enviar transação de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }

            //
            // Verificar erros no lote
            //
            if (response.internalResponses.Count(m => m.success == false) == 0)
            {
                //
                // O registro só será alterado se não houver erros
                //
                // entity.status = Product.ProductIntegrationStatus.Created;
                record   = toJson(entity);
                response = await _serviceLayerConnector.Patch($"U_VSITPRODUCT_COMP('{entity.RecId}')", record, true);

                if (!response.success)
                {
                    string message = $"Erro ao inserir dados em '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";

                    Console.WriteLine(message);
                    throw new ApplicationException(message);
                }
            }
            else
            {
                // Erro no cabeçalho do produto
                if (response.internalResponses.Count == 1)
                {
                    string message = $"Erro ao inserir dados em '{entity.EntityName}': {response.internalResponses[0].errorCode}-{response.internalResponses[0].errorMessage}";
                    Console.WriteLine(message);
                    throw new ApplicationException(message);
                }
                else
                {
                    int position = response.internalResponses.Count - 1;
                    //int item = position - 1;

                    //string message = $"Erro ao inserir dados em '{entity.items[0].EntityName}' item {entity.items[item].itemId} : {response.internalResponses[position].errorCode}-{response.internalResponses[position].errorMessage}";
                    //Console.WriteLine(message);
                    throw new ApplicationException("Vazio");
                }
            }
        }
Пример #13
0
        async public Task Insert(BusinessPlaces entity)
        {
            IBatchProducer batch    = _serviceLayerConnector.CreateBatch();
            string         codigoWH = criaCodigoWareHouses(entity.BPLName, entity.BPLID.ToString(), "01");

            entity.DefaultWarehouseID         = codigoWH;
            entity.DefaultResourceWarehouseID = codigoWH;
            string recordWareHouses = toJsonwarehouses(entity.BPLName, codigoWH);

            batch.Post(HttpMethod.Post, "/Warehouses", recordWareHouses);
            ServiceLayerResponse response = await _serviceLayerConnector.Post("Warehouses", recordWareHouses);

            codigoWH = criaCodigoWareHouses(entity.BPLName, entity.BPLID.ToString(), "99");
            //entity.DefaultWarehouseID = codigoWH;
            //entity.DefaultResourceWarehouseID = codigoWH;
            recordWareHouses = toJsonwarehouses(entity.BPLName, codigoWH);
            batch.Post(HttpMethod.Post, "/Warehouses", recordWareHouses);
            response = await _serviceLayerConnector.Post("Warehouses", recordWareHouses);

            //businessPlaces
            batch = _serviceLayerConnector.CreateBatch();
            entity.BPLNameForeign = entity.BPLName;
            string record = toJson(entity);

            batch.Post(HttpMethod.Post, "/BusinessPlaces", record);
            response = await _serviceLayerConnector.Post("BusinessPlaces", record);

            if (entity.CardCode.Contains("D"))
            {
            }
            //businesspartners F
            entity.CardType = "cSupplier";
            record          = toJsonPartners(entity, "F");
            batch.Post(HttpMethod.Post, "/BusinessPartners", record);
            response = await _serviceLayerConnector.Post("BusinessPartners", record);

            //businesspartners C
            entity.CardType = "cCustomer";
            record          = toJsonPartners(entity, "C");
            batch.Post(HttpMethod.Post, "/BusinessPartners", record);
            response = await _serviceLayerConnector.Post("BusinessPartners", record);

            //descomentar daqui pra baixo
            //IBatchProducer batch = _serviceLayerConnector.CreateBatch();
            //string codigoWH = criaCodigoWareHouses(entity.BPLName, entity.BPLID.ToString(), "01");
            //entity.DefaultWarehouseID = codigoWH;
            //entity.DefaultResourceWarehouseID = codigoWH;
            //string recordFiliais = toJson(entity);
            //string recordWareHouses = toJsonwarehouses(entity.BPLName, codigoWH);
            //batch.Post(HttpMethod.Post, "/Warehouses", recordWareHouses);
            //batch.Post(HttpMethod.Post, "/BusinessPlaces", recordFiliais);
            //ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);


            if (!response.success && !(response.errorMessage.Contains("1320000140")))
            {
                string message = $"Erro ao enviar transação de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
            else
            {
                var    idEntidade = entity.RecId;
                var    cad        = toJsonEntidades();
                string query      = Global.BuildQuery($"U_VSITENTIDADE('{idEntidade}')");
                response = await _serviceLayerConnector.Patch(query, cad, true);
            }
        }