<?php

//essa função soma todas as colunas e armarzena na coluna total do db
//deixar o banco sem null
//UPDATE `stock` SET `nome_doca`=0 WHERE `nome_doca` IS null;

include_once '../config.php';
include_once '../../env.php';


function total(){

    global $entityManager;

    $stockRepository = $entityManager->getRepository('App\Models\Entity\StockDb');
    $stock = $stockRepository->findAll();

    $quantArray = count($stock);
    //$quantArray = 5;

    for ($i=0; $i < $quantArray; $i++) { 
        
        $stockTotal[$i] = $stock[$i]->getTotal();
        
        $stockFabrica[$i] = $stock[$i]->getOutletCvto();
        $stockForMen[$i] = $stock[$i]->getForMen();
        $stockMaiusculo[$i] = $stock[$i]->getMaiusculo();
        $stockLife[$i] = $stock[$i]->getLife();
        $stockVestylle[$i] = $stock[$i]->getVestylle();
        $stockHaut[$i] = $stock[$i]->getHaut();
        $stockDimazzo[$i] = $stock[$i]->getDimazzo();
        $stockDimazzoArapongas[$i] = $stock[$i]->getDimazzoArapongas();
        $stockBhPadilha[$i] = $stock[$i]->getBhPadilha();
        $stockOrigem[$i] = $stock[$i]->getOrigem();
        $stockEmporio[$i] = $stock[$i]->getEmporio();
        $stockAbusiva[$i] =  $stock[$i]->getAbusiva();
        $stockSignoriOtto[$i] =  $stock[$i]->getSignoriOtto();
        $stockGianottoModas[$i] =  $stock[$i]->getGianottoModas();



        $novoStock[$i] = $stockFabrica[$i] + $stockForMen[$i] + $stockMaiusculo[$i] + $stockLife[$i] + $stockVestylle[$i] + $stockHaut[$i] + $stockDimazzo[$i]+ $stockDimazzoArapongas[$i]  + $stockBhPadilha[$i] + $stockOrigem[$i] + $stockEmporio[$i] + $stockAbusiva[$i] + $stockSignoriOtto[$i] + $stockGianottoModas[$i];

        var_dump($novoStock[$i]);

        $total = $stock[$i]->setTotal($novoStock[$i]);
        $entityManager->persist($total);
        $entityManager->flush();  


    }
    
}

total();
