Get information from an array inside a foreach - PHP

5

Good afternoon.

I'm developing an application with PHP using Laravel, and I'm having a hard time.

I have a table with the name of Account, in which it has the code of this account, represented by the variable $ client-> Code, also has the client's CNPJ and the corporate name represented by the variable $ client-> ClientRoot.

I've created an array of CPNJ's of clients. I am giving a select in the table in which the information of these clients is found, and according to the cnpj of the array, I want to get the information from that client to insert them in my insert.

Currently my insert is working, but the variable $ client-> Code is being entered the value of 1 for all clients (each client has a unique code) and the $ client-> ClientRacer does not come up with anything. I'm doing something wrong, but I do not know what it is.

Link to the image of the cute code in the visual code for better visualization: Link imgur

NOTE: The variable $data->Nfse->InfNfse->TomadorServico->IdentificacaoTomador->CpfCnpj->Cnpj that is in if, is the CNPJ field coming from a JSON file.

Follow the code:

//select na tabela Conta, no qual consta todas as informações dos clientes
(cnpj, código, razão social etc..)

$pesquisaClientes = DB::connection('sqlsrv2')->select('SELECT * FROM 
ConsultaCnpj.dbo.Conta');

    // array dos CNPJ's dos clientes
    $CnpjClientes = array("43185230000185", "43037969000140", "52391703000191", "00697722000147", "35259696000150", "14189856000161", "11684590000135",
    "00299388000173", "12515276000191", "73800260000115", "26562892000108", "04711149000130", "11888864000108", "24193260000199", "34482091000160", 
    "10638562000119", "15615776000193", "22165071000187", "02505297000172", "03662446000170", "07863214000130", "34639419000100", "26619841000175", 
    "13738204000176", "62021837000174", "24417008000116", "11005444000136", "08303182000181", "84318799000159", "04768671000158", "00593411000138", 
    "06572788000197", "03875295000138", "08332733000135", "00237222000122", "06272868000127", "08336841000186", "04734406000159", "07647181000191", 
    "04769874000169", "08506339000176", "27149095000166", "34476101000155", "84042423000164", "13161344000124", "26753715000109", "23498256000176", 
    "00577473000156", "11425519000138", "90601147000120", "08077490000136", "04185220000198", "01646861000104", "02116365000101", "05379164000195", 
    "56319882000107", "15678394000109", "00581009000133", "08641589000119", "34918342000107", "11674272000193", "07801011000110", "30892350000170", 
    "87070843000142", "10456659000100", "44407989000128", "10338929000189", "06186786000160", "11674751000100", "08299638000187", "06274668000103", 
    "11578277000112", "73603748000152", "73392409000174", "05644027000130", "56321573000171", "60993482000150", "00085803000196", "87096616000196", 
    "57352635000175", "33658204000173");

    foreach ($pesquisaClientes as $cliente) {

            if (in_array($data->Nfse->InfNfse->TomadorServico->IdentificacaoTomador->CpfCnpj->Cnpj, $CnpjClientes)) {

                //insert conta de debito (cliente)
                DB::insert('insert into LancaContaContabil (Codigo, DataOper, DespRateio, Valor, Receita, AgenteCobrador, 
                DespHistorico, Complemento, Orcado, Encerrado, CodigoContaContabil, LoteLanca,
                Rascunho, DC) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)', 
                array($ult+1, $data->Nfse->InfNfse->Competencia, NULL, $data->Nfse->InfNfse->Servico->Valores->ValorServicos,
                0, NULL, 9182, $numero_nota . ', ' . $cliente->ClienteRazao, 0, 0, $cliente->Codigo, $lanca, 0, 'D'));

            }
    
asked by anonymous 28.10.2017 / 17:55

0 answers