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; }
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; }