I'm developing an application with PHP using Laravel, and I have a problem.
I have a table with the name Account, in which it has a Code, CNPJ, ClientName columns (among others).
I've created an array of CNPJ's of clients (CNPJ is a unique identification of 14 characters for each client). I am giving a select in the table in which the information of these clients is located, and according to the cnpj of the array, I want to take the information of that client from my table to use them in my insert.
Currently my insert is working, but the variable $client->code is being inserted the value of 1 for all clients (each client has a unique code) and the $client->ClientName is returning null. I'm doing something wrong, but I do not know what it is.
Here is the output for the $client object:
stdClass Object ( [Number] => 1.0.0.00.00 [Status] => ACTIVE[ShortNumber] => 17 [Code] => 1 [Cnpj] => [ClientName] => )
OBS: this output information is from the first record in my table. For some reason, my array is being ignored.
OBS2: the variable $data-> Nfse->InfNfse->Service->Service->CpfCnpj->Cnpj is from an outside source, contains the CNPJ of a client (the unique identification of 14 characters for each client).
Heres the code:
$selectClients = DB::connection('sqlsrv2')->select('SELECT * FROM ConsultaCnpj.dbo.Account');
$cnpjClients = 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 ($selectClients as $client) {
if (in_array($data->Nfse->InfNfse->TomadorServico->IdentificacaoTomador->CpfCnpj->Cnpj, $cnpjClients)) {
//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 . ', ' . $client->ClientName, 0, 0, $client->Code, $lanca, 0, 'D'));
}
}
Thanks guys.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire