Last active
August 16, 2021 04:33
-
-
Save AgungPambudi/dabfccaf744672755c1b7efd0716fb59 to your computer and use it in GitHub Desktop.
Simple logic with php loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#author : Agung Pambudi | |
#email : mail@agungpambudi.com | |
#version : 0.2 | |
# | |
#KyusuMart Planogram Analysis | |
#============================================================================== | |
# _ _ _ | |
# ___ ___ _ _ ___ ___ ___ ___ _____| |_ _ _ _| |_| ___ ___ _____ | |
#| .'| . | | | | . | . | .'| | . | | | . | |_| _| . | | | |
#|__,|_ |___|_|_|_ | _|__,|_|_|_|___|___|___|_|_|___|___|_|_|_| | |
# |___| |___|_| | |
$firstday = 01; | |
$secondday = 15; | |
for($day = (int)$firstday; $day <= (int)$secondday; $day++) { // means : day = 1 day <= 15 | |
$table_planogram = "largeplanogram_" . substr($year, 2, 2) . $month . (($day < 10) ? "0" . $day : $day); // largeplanogram_211215 | |
$table_sliplocationproduct = "sliplocationproduct_" . substr($year, 2, 2) . $month . (($day < 10) ? "0" . $day : $day); // sliplocationproduct_211215 | |
$updated_date = "$year-$month-" . (($day < 10) ? "0" . $day : $day); // if $day < 10 then 01,02,03,04,05 else 11,12,13,14,15,16,17 | |
$sqlquery = mysql_query("SELECT FIRST_ALIAS.effectiveDate, activeStore, indStore, allItem, qtyINDStore, qtyINDStore/allItem*100 AS percent, qtyINDStore/activeStore AS averageStore, indStore/activeStore*100 AS indAudit, stockOut FROM ( SELECT effectiveDate, SUM(allItem) AS allItem FROM ( SELECT '$updated_date' AS effectiveDate, store, COUNT(product_code) AS allItem FROM $table_planogram WHERE planogramStatus IN ('B','I') GROUP BY store) alias_table GROUP BY effectiveDate) FIRST_ALIAS, (SELECT effectiveDate, SUM(ind) AS qtyINDStore FROM ( SELECT '$updated_date' AS effectiveDate, store, COUNT(product_code) AS indItem FROM $table_planogram WHERE planogramStatus='I' AND productType='TT' AND stock <> 0 GROUP BY store) alias_table GROUP BY effectiveDate) SECOND_ALIAS, (SELECT effectiveDate, COUNT(store) AS indStore FROM ( SELECT '$updated_date' AS effectiveDate, store FROM $table_planogram WHERE planogramStatus='B' GROUP BY store) alias_table GROUP BY effectiveDate) THIRD_ALIAS, (SELECT effectiveDate, COUNT(store_code) AS activeStore FROM ( SELECT '$updated_date' AS effectiveDate, store_code, `cost` FROM $table_sliplocationproduct WHERE `code` = 14 AND `cost` > 5 GROUP BY store_code) alias_table GROUP BY effectiveDate) FOURTH_ALIAS, (SELECT effectiveDate, AVG(`cost`) AS stockOut FROM ( SELECT '$updated_date' AS effectiveDate, store_code, `cost` FROM $table_sliplocationproduct WHERE `code` = 17 GROUP BY store_code) alias_table GROUP BY effectiveDate) FIFTH_ALIAS WHERE FIRST_ALIAS.effectiveDate = SECOND_ALIAS.effectiveDate AND FIRST_ALIAS.effectiveDate = THIRD_ALIAS.effectiveDate AND FIRST_ALIAS.effectiveDate = FOURTH_ALIAS.effectiveDate AND FIRST_ALIAS.effectiveDate = FIFTH_ALIAS.effectiveDate", $databaseconnection); | |
echo mysql_error(); | |
while($resultset = mysql_fetch_array($sqlquery)) { | |
$store_result_to_array[$resultset['effectiveDate']] = $resultset; // store data from database into array | |
} | |
} | |
// how to use above logic | |
for($day = (int)$firstday; $day <= (int)$secondday; $day++) { | |
$generated_date = "$year-$month-" . (($day < 10) ? "0" . $day : $day); // if $day < 10 then 01,02,03,04,05 else 11,12,13,14,15 | |
$store_result_to_array[$generated_date][1]; // showing data from activeStore column. | |
$store_result_to_array[$generated_date][2]; // showing data from indStore column. | |
number_format($store_result_to_array[$generated_date][3]); // showing data from allItem column. allItem column contain number | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment