0
I’m trying to calculate expenses in the system but I’m not succeeding. The system works as follows, the User makes an order involving 1 or more products, these orders are stored in a table. Each Product registered in the system is stored in another table, having the standard fields, in stock, unitary cost, already sent and pending. The User has two tables, one for the Branch he manages and the other is the users account.
The problem is, having order value for each branch. That is, add up how many items of the product were sent to the affiliate and then multiply by the cost of it, and finally, add up the entire result to display the total expense of the affiliate at the time.
I tried using while
however it exhibited several times the same product in different quantities to the same affiliate.
SUBTITLES
subsidiaries = table where all registered subsidiaries are;
stationary items = table where the products are;
stationary requests = table where the orders are;
requested file = table where the products requested in the order are;
qnt_sent = Quantity Sent;
cost = Unitary cost per product;
chns = Unique code for each data registered in the system, works as a protocol number.
PHP I am using PDO for connection
$procura_filial = $site->query("SELECT * FROM filiais ORDER BY codigo ASC");
while ($filiais = $procura_filial->fetch(PDO::FETCH_OBJ)) {
$procura_solicitacoes = $site->query("SELECT * FROM papelaria_solicitacoes WHERE filial = '$filiais->chns'");
if ($procura_solicitacoes->rowCount() <= 0) {
}else {
while($solicitacoes = $procura_solicitacoes->fetch(PDO::FETCH_OBJ)){
$procura_solicitados = $site->query("SELECT * FROM papelaria_solicitados WHERE chns = '$solicitacoes->chns'");
while ($solicitados = $procura_solicitados->fetch(PDO::FETCH_OBJ)) {
$reprocura_solicitados = $site->query("SELECT * FROM papelaria_solicitados WHERE filial = '$solicitados->filial' and produtos = '$solicitados->produtos'");
//SOMA QUANTIDADE ENVIADA DE CADA PRODUTO
while($soma_qnt = $reprocura_solicitados->fetch(PDO::FETCH_OBJ)){
$val1 = $soma_qnt->qnt_enviada;
$total_cont += $val1;
$total_produto_env = $total_cont;
}
}
}
}
echo "Filial: ".$soma_qnt->filial." Produto: ".$soma_qnt->produtos." Enviados: ".$total_produto_env."<br>";
}
Rodrigo, could you explain to me better your suggestion, I did not understand right.
– Thomas Franklin
Which part you didn’t understand right?
– Rodrigo Bezerra Rodrigues