Beispiel #1
0
 }
 $_SESSION['DATA_ETAT']['exercice'] = $_POST['exercice'];
 $_SESSION['DATA_ETAT']['ligne'] = array();
 $_SESSION['DATA_ETAT']['WHERE'] = $whereAll;
 $_SESSION['DATA_ETAT']['DATEJ'] = $_POST['datedebut'];
 $_SESSION['DATA_ETAT']['DATEF'] = $_POST['datefin'];
 $_SESSION['DATA_ETAT']['QTE_T_ENTREE'] = 0;
 $_SESSION['DATA_ETAT']['QTE_T_SORTIE'] = 0;
 //Stock courant
 $d1 = mysqlFormat($_SESSION['GL_USER']['DEBUT_EXERCICE']);
 $d2 = mysqlFormat($_POST['datedebut']);
 //	$d3= date($d2 , mktime(0,0,0,date("y"), date("d")-2,date("m") ));
 //	echo $d3;
 //	break;
 $Entree = StockProduitPeriode($_POST['produit'], 'E', $d1, $d2, " AND  mouvement.CODE_MAGASIN LIKE '" . $_SESSION['GL_USER']['MAGASIN'] . "' ");
 $Sortie = StockProduitPeriode($_POST['produit'], 'S', $d1, $d2, " AND  mouvement.CODE_MAGASIN LIKE '" . $_SESSION['GL_USER']['MAGASIN'] . "' ");
 $StockPrecedent = $Entree['QTE'] - $Sortie['QTE'];
 $_SESSION['DATA_ETAT']['STOCK'] = $StockPrecedent;
 $sql = "SELECT * FROM mouvement INNER JOIN produit ON (mouvement.CODE_PRODUIT LIKE produit.CODE_PRODUIT)\r\n\t\t\t {$whereAll} ORDER BY produit.PRD_LIBELLE, mouvement.ID_MOUVEMENT, mouvement.MVT_DATE ASC; ";
 $query = $cnx->prepare($sql);
 //Prepare the SQL
 $query->execute();
 //Execute prepared SQL => $query
 while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
     //echo  'Ent'.$entree.' Sort'.$sortie.'<br>';
     if (isset($row['MVT_TYPE']) && $row['MVT_TYPE'] == 'E') {
         $StockPrecedent += $row['MVT_QUANTITE'];
         array_push($_SESSION['DATA_ETAT']['ligne'], array('codeproduit' => $row['CODE_PRODUIT'], 'reflot' => $row['MVT_REFLOT'], 'produit' => addslashes($row['PRD_LIBELLE']), 'nature' => $row['MVT_NATURE'], 'typemvt' => $row['MVT_TYPE'], 'qteentree' => $row['MVT_QUANTITE'], 'qtesortie' => 0, 'dateentree' => frFormat2($row['MVT_DATE']), 'dateperemp' => $row['MVT_DATEPEREMP'], 'pa' => $row['MVT_PA'], 'pv' => $row['MVT_PV'], 'unite' => $row['ID_UNITE'], 'stock' => $StockPrecedent, 'etat' => $row['MVT_VALID']));
         $tEntree += $row['MVT_QUANTITE'];
     }
     if (isset($row['MVT_TYPE']) && $row['MVT_TYPE'] == 'S') {
function CMM($prdt, $whereAll)
{
    $d1 = date('Y-m-d');
    $d3 = date("Y-m-d", mktime(0, 0, 0, date("m") - 3, date("d"), date("y")));
    $dlim = $_SESSION['GL_USER']['DEBUT_EXERCICE'];
    //
    $date1 = new DateTime($d1);
    $date3 = new DateTime($d3);
    $datelim = new DateTime($dlim);
    $t1 = intval($date1->format('m'));
    $t3 = intval($date3->format('m'));
    $tlim = intval($datelim->format('m'));
    $cond = $t1 - $tlim;
    $i = 1;
    while ($i < 4) {
        $qte3 = StockProduitPeriode($prdt, 'S', $d3, $d1, $whereAll);
        $qteDecl3 = StockProduitDeclassePeriode($prdt, 'S', $d3, $d1, $whereAll);
        $cmm = ($qte3['QTE'] - $qteDecl3['QTE']) / 3;
        if ($cmm <= 0) {
            $i++;
            $d1 = $d3;
            $d3 = date("Y-m-d", mktime(0, 0, 0, date("m") - 3 * $i, date("d"), date("y")));
            $date1 = new DateTime($d1);
            $t1 = intval($date1->format('m'));
        } else {
            $i = 5;
        }
    }
    return $cmm;
}
function CMM($prdt, $whereAll)
{
    $d1 = date('Y-m-d');
    $d3 = date("Y-m-d", mktime(0, 0, 0, date("m") - 1, date("d"), date("y")));
    $dlim = $_SESSION['GL_USER']['DEBUT_EXERCICE'];
    //
    $date1 = new DateTime($d1);
    $date3 = new DateTime($d3);
    $datelim = new DateTime($dlim);
    $t1 = intval($date1->format('m'));
    $t3 = intval($date3->format('m'));
    $tlim = intval($datelim->format('m'));
    $tdeb = intval($date1->format('m'));
    $cond = '0';
    $fin = '0';
    $dif = '';
    $cmmc = '0';
    $cmm = '0';
    $i = 1;
    $j = 0;
    while ($cond == $fin) {
        $qte3 = StockProduitPeriode($prdt, 'S', $d3, $d1, $whereAll);
        $qteDecl3 = StockProduitDeclassePeriode($prdt, 'S', $d3, $d1, $whereAll);
        $cmmc = $qte3['QTE'] - $qteDecl3['QTE'];
        //	$cmm = ($qte3['QTE'] - $qteDecl3['QTE'])/3;
        if ($cmmc != 0) {
            $cmm = $cmm + $cmmc;
            $j = $j + 1;
            $i++;
            $d1 = $d3;
            $d3 = date("Y-m-d", mktime(0, 0, 0, date("m") - 1 * $i, date("d"), date("y")));
            $date1 = new DateTime($d1);
            $date3 = new DateTime($d3);
            $t1 = intval($date1->format('m'));
            $t3 = intval($date3->format('m'));
        } else {
            $i++;
            $d1 = $d3;
            $d3 = date("Y-m-d", mktime(0, 0, 0, date("m") - 1 * $i, date("d"), date("y")));
            $date1 = new DateTime($d1);
            $date3 = new DateTime($d3);
            $t1 = intval($date1->format('m'));
            $t3 = intval($date3->format('m'));
        }
        $dif = $tdeb - $i;
        if ($j == 3 or $dif == 1) {
            if ($cmm != 0) {
                $cmm = $cmm / $j;
            }
            $cond = '1';
        }
    }
    //echo ' j='.$j.' i='.$i.'  deb   :'.$tdeb.'  dif='.$dif.'   cmm='.$cmm.'  con: '.$whereAll.' D1 :'.$d1.'  D3 :'.$d3;
    //break;
    return $cmm;
}
function CMM($prdt, $whereAll)
{
    $d1 = date('Y-m-d');
    $d3 = date("Y-m-d", mktime(0, 0, 0, date("m") - 3, date("d"), date("y")));
    $qte3 = StockProduitPeriode($prdt, 'S', $d3, $d1, $whereAll);
    $qteDecl3 = StockProduitDeclassePeriode($prdt, 'S', $d3, $d1, $whereAll);
    $cmm = ($qte3['QTE'] - $qteDecl3['QTE']) / 3;
    return $cmm;
}
     $whereAll = 'AND ' . $in . $where;
     if ($in != '') {
         $in = ' WHERE ' . substr($in, 0, strlen($in) - 4);
     }
     $_SESSION['DATA_ETAT']['exercice'] = $_POST['exercice'];
     $_SESSION['DATA_ETAT']['ligne'] = array();
     $_SESSION['DATA_ETAT']['WHERE'] = $whereAll;
     isset($_POST['datedebut']) && $_POST['datedebut'] != '' ? $d1 = mysqlFormat(trim($_POST['datedebut'])) : ($d1 = '');
     isset($_POST['datefin']) && $_POST['datefin'] != '' ? $d2 = mysqlFormat(trim($_POST['datefin'])) : ($d2 = '');
     $sql = "SELECT * FROM produit  {$in} ORDER BY produit.PRD_LIBELLE ASC; ";
     $query = $cnx->prepare($sql);
     //Prepare the SQL
     $query->execute();
     //Execute prepared SQL => $query
     while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
         $qte = StockProduitPeriode($row['CODE_PRODUIT'], 'S', $d1, $d2, $whereAll);
         //echo  'Ent'.$entree.' Sort'.$sortie.'<br>';
         array_push($_SESSION['DATA_ETAT']['ligne'], array('codeproduit' => $row['CODE_PRODUIT'], 'produit' => addslashes($row['PRD_LIBELLE']), 'qte' => $qte['QTE'], 'unite' => $row['ID_UNITE'], 'prix' => $row['PRD_PRIXVENTE']));
     }
     $_SESSION['DATA_ETAT']['nbreLigne'] = $query->rowCount();
     //print_r($_SESSION['DATA_ETAT']);
     header('location:rapconsommation1.php?selectedTab=rap');
     break;
 case 'rapdeclassement':
     $where = "";
     $whereAll = "";
     isset($_POST['exercice']) && $_POST['exercice'] != '' ? $where .= "mouvement.ID_EXERCICE = '" . addslashes(trim($_POST['exercice'])) . "' AND " : ($where .= "");
     isset($_POST['datedebut']) && $_POST['datedebut'] != '' ? $where .= "mouvement.MVT_DATE > '" . addslashes(mysqlFormat(trim($_POST['datedebut']))) . "' AND " : ($where .= "");
     isset($_POST['datefin']) && $_POST['datefin'] != '' ? $where .= "mouvement.MVT_DATE <= '" . addslashes(mysqlFormat(trim($_POST['datefin']))) . "' AND " : ($where .= "");
     isset($_POST['produit']) ? $produit = $_POST['produit'] : ($produit = array());
     isset($_POST['categorie']) && $_POST['categorie'] != '0' ? $categorie = $_POST['categorie'] : ($categorie = '');