$sql = "INSERT INTO \"tbl_invQuantity\" ( "; $sql .= " \"boxId\",\"mainSizeId\",\"optSizeId\",\"qty\",\"conveyor_slot\") VALUES ("; $sql .= "'".$unit['id']."','".$mainSizeId[$key]."','".$optSizeId[$key]."','".$qty[$key]."','".$conveyorSlotHid[$key]."' )"; ============================================================================ pg_last_error($connection), 'success' => false, 'code' => 500 ]); return; } $unit = pg_fetch_array($result); pg_free_result($result); if($unit != ''){ foreach ($qty as $q){ if($q < 0){ echo json_encode([ 'message' => 'Negative values not allowed', 'success' => false, 'code' => 400 ]); return; } } $count = 0; foreach ($is_change as $key=>$change){ if($change == 1){ if($count == 0){ $sql = ''; $sql = 'INSERT INTO "tbl_invUpdateLog" ('. ' "boxId","styleId","createdBy","createdAt",type ) VALUES ('. "'".$unit['box']."','".$styleId."','".$_SESSION['employeeID']."','".date('Y-m-d G:i:s')."','Update Box' ) RETURNING *"; if(!($result=pg_query($connection,$sql))){ echo json_encode([ 'message' => pg_last_error($connection), 'success' => false, 'code' => 500 ]); return; } $log = pg_fetch_array($result); pg_free_result($result); } $mainSize = $mainSizeId[$key]; $optSize = $optSizeId[$key]; $sql = ''; $sql = 'SELECT * FROM "tbl_invQuantity" WHERE "boxId"='.$unit['id'].' and "mainSizeId"='.$mainSize.' and "optSizeId"='.$optSize; if(!($result=pg_query($connection,$sql))){ echo json_encode([ 'message' => pg_last_error($connection), 'success' => false, 'code' => 500 ]); return; } $mainSizeName = getSizeName($mainSize,"mainSize",$connection); $optSizeName = (getSizeName($optSize,"opt1size",$connection) == NULL)?"qty":getSizeName($optSize,"opt1size",$connection); $quantity = pg_fetch_array($result); if($quantity != null){ if($qty[$key] != $quantity['qty']){ $sql = ''; $sql = 'UPDATE "tbl_invQuantity" SET '; $sql .= ' qty='.$qty[$key]; $sql .= ' WHERE id='.$quantity['id']; $count++; $sql2 = ''; $sql2 = 'INSERT INTO "tbl_invUpdateLogQuantity" ('. '"mainSize","optSize","logId","oldValue","newValue","log", "conveyor_slot" ) VALUES ( '. "'".$mainSize."','".$optSize."','".$log['id']."','".$quantity['qty']."','".$qty[$key]."','Update Box','".$conveyorSlotHid[$key]."' )"; if(!($audit = pg_query($connection,$sql2))){ echo json_encode([ 'message' => pg_last_error($connection), 'success' => false, 'code' => 500 ]); return; } pg_free_result($audit); $sql1 = ''; $sql1 = "INSERT INTO \"audit_logs\" ("; $sql1 .= " \"inventory_id\", \"employee_id\", \"updated_time\","; $sql1 .= " \"log\") VALUES ("; $sql1 .= " '" . $styleId . "' "; $sql1 .= ", '". $_SESSION['employeeID'] ."'"; $sql1 .= ", '". date('U') ."'"; $sql1 .= ", 'Update Quantity From ".$quantity['qty']." To ".$qty[$key]." for Scale ".$mainSizeName." - ".$optSizeName." in box: ".$unit['box']." '"; $sql1 .= ")"; if(!($audit = pg_query($connection,$sql1))){ echo json_encode([ 'message' => pg_last_error($connection), 'success' => false, 'code' => 500 ]); return; } pg_free_result($audit); } } else { $sql = ''; $sql = 'INSERT INTO "tbl_invQuantity" ( '; $sql .= '"boxId","mainSizeId","optSizeId","qty","conveyor_slot" ) VALUES ('; $sql .= " '".$unit['id']."','".$mainSize."','".$optSize."','".$qty[$key]."','".$conveyorSlotHid[$key]."' ) "; $count++; $sql2 = ''; $sql2 = 'INSERT INTO "tbl_invUpdateLogQuantity" ('. '"mainSize","optSize","logId","oldValue","newValue","log","conveyor_slot" ) VALUES ( '. "'".$mainSize."','".$optSize."','".$log['id']."','0','".$qty[$key]."','Update Box','".$conveyorSlotHid[$key]."' )"; if(!($audit = pg_query($connection,$sql2))){ echo json_encode([ 'message' => pg_last_error($connection), 'success' => false, 'code' => 500 ]); return; } pg_free_result($audit); $sql1 = ''; $sql1 = "INSERT INTO \"audit_logs\" ("; $sql1 .= " \"inventory_id\", \"employee_id\", \"updated_time\","; $sql1 .= " \"log\") VALUES ("; $sql1 .= " '" . $styleId . "' "; $sql1 .= ", '". $_SESSION['employeeID'] ."'"; $sql1 .= ", '". date('U') ."'"; $sql1 .= ", 'Update Quantity From 0 To ".$qty[$key]." for Scale ".$mainSizeName." - ".$optSizeName." in box: ".$unit['box']." '"; $sql1 .= ")"; if(!($audit = pg_query($connection,$sql1))){ echo json_encode([ 'message' => pg_last_error($connection), 'success' => false, 'code' => 500 ]); return; } pg_free_result($audit); } if(!($result=pg_query($connection,$sql))){ echo json_encode([ 'message' => pg_last_error($connection), 'success' => false, 'code' => 500 ]); return; } } } if($count > 0 ){ echo json_encode([ 'message' => 'Box Updated Successfully', 'success' => true, 'code' => 200 ]); return; } else { echo json_encode([ 'message' => 'Box Already Updated', 'success' => true, 'code' => 202 ]); return; } } else { echo json_encode([ 'message' => 'Box Not Found', 'success' => false, 'code' => 500 ]); return; } ?> $element .= ''; $element .= ''; if(isset($dataConveyor[$key2][0]) && !empty($dataConveyor[$key2][0])){ $element .= 'Edit slot'; $element .='

'.$dataToolTip[$key2][0]."
Conveyor slot: " . $dataConveyor[$key2][0].'

'; }else{ $element .= 'Set slot'; $element .='

'.$dataToolTip[$key2][0].'

'; } $element .= ''; =====================================new work saved worked================================================================ Failed style Query:

' . pg_last_error($connection) . '

'; exit; } $dataStyle = pg_fetch_array($resultStyle); /*echo '
';
    print_r($dataStyle);
    echo '
';*/ pg_free_result($resultStyle); //GET COLOR DATA $query = ''; $query = 'Select * from "tbl_invColor" where "styleId"=' . $dataStyle['styleId']; if (!($resultColor = pg_query($connection, $query))) { print("

Failed Color Query:

" . pg_last_error($connection)) . '

'; exit; } while ($row = pg_fetch_array($resultColor)) { $dataColor[] = $row; } pg_free_result($resultColor); //Fetch All Information for the style $sql = ''; $sql = 'SELECT style.*,garment.*,client.* FROM "tbl_invStyle" style ' . ' LEFT JOIN "tbl_garment" garment on garment."garmentID" = style."garmentId" ' . ' LEFT JOIN "clientDB" client on client."ID" = style."clientId" ' . ' WHERE style."styleId"=' . $_GET['styleId']; if (!($resultInfo = pg_query($connection, $sql))) { echo '

Failed Info Query:

' . pg_last_error($connection) . '

'; exit; } $dataInfo = pg_fetch_array($resultInfo); pg_free_result($resultInfo); //Fetch Size Scale Data if ($dataStyle['scaleNameId'] != '') { //Fetch Main size $query2 = 'Select "sizeScaleId" as "mainSizeId", "scaleSize" from "tbl_invScaleSize" where "scaleId"=' . $dataStyle['scaleNameId'] . ' and "scaleSize" IS NOT NULL and "scaleSize" <>\'\' order by "mainOrder","sizeScaleId"'; if (!($result2 = pg_query($connection, $query2))) { print("Failed OptionQuery: " . pg_last_error($connection)); exit; } while ($row2 = pg_fetch_array($result2)) { $dataMainSize[] = $row2; } pg_free_result($result2); //Fetch Opt size $query2 = 'Select "sizeScaleId" as "opt1SizeId", "opt1Size" from "tbl_invScaleSize" where "scaleId"=' . $dataStyle['scaleNameId'] . ' and "opt1Size" IS NOT NULL and "opt1Size" <>\'\' order by "opt1Order","sizeScaleId"'; if (!($result2 = pg_query($connection, $query2))) { print("Failed OptionQuery: " . pg_last_error($connection)); exit; } while ($row2 = pg_fetch_array($result2)) { $dataOptSize[] = $row2; } pg_free_result($result2); $dataOptSizeId = array(); foreach ($dataOptSize as $key => $val) { if (isset($val['opt1SizeId'])) { $dataOptSizeId[(int)$val['opt1SizeId']] = $val['opt1Size']; } } $dataMainSizeId = array(); foreach ($dataMainSize as $key => $val) { if (isset($val['mainSizeId'])) { $dataMainSizeId[(int)$val['mainSizeId']] = $val['scaleSize']; } } } else { echo '

No size available

'; die(); } //Fetch All Location $sql = ''; $sql = 'SELECT details.*,location.* FROM "locationDetails" details ' . 'INNER JOIN "tbl_invLocation" location on location."locationId" = CAST(details."locationId" as INT)' . ' ORDER BY details."locationId" DESC'; if (!($result = pg_query($connection, $sql))) { print("Failed location fetch Query: " . pg_last_error($connection)); exit; } while ($row2 = pg_fetch_array($result)) { $allStorage[] = $row2; } pg_free_result($result); //Create actual array from the all storage $allLocation = []; if (count($allStorage) > 0) { foreach ($allStorage as $key => $value) { $allLocation[$key]['storageId'] = $value['id']; $allLocation[$key]['locationId'] = $value['locationId']; $allLocation[$key]['locationIdentifier'] = $value['identifier']; if ($value['warehouse'] != '') { $allLocation[$key]['storage'] = $value['warehouse']; $allLocation[$key]['type'] = 'warehouse'; } elseif ($value['container'] != '') { $allLocation[$key]['storage'] = $value['container']; $allLocation[$key]['type'] = 'container'; } else { $allLocation[$key]['storage'] = $value['conveyor']; $allLocation[$key]['type'] = 'conveyor'; } } } //Fetch all information for the unit $sql = ''; $sql = 'SELECT unit.*,details.*,location.* FROM "tbl_invUnit" unit' . ' INNER JOIN "locationDetails" details on details.id= unit."storageId" ' . ' INNER JOIN "tbl_invLocation" location on location."locationId"= CAST(details."locationId" as bigint)' . ' where unit."styleId"=' . $_GET['styleId']; if (isset($_GET['colorId']) && $_GET['colorId'] != 0) { $sql .= ' and unit."colorId"=' . $_GET['colorId']; } else { $sql .= ' and unit."colorId"=' . $dataColor[0]['colorId']; } $sql .= ' and unit.merged=0'; $sql .= ' ORDER BY unit.box ASC'; if (!($result = pg_query($connection, $sql))) { print("Failed location fetch Query: " . pg_last_error($connection)); exit; } while ($row2 = pg_fetch_array($result)) { $allUnit[] = $row2; } pg_free_result($result); //Fetch Latest updated records for a Style $sql = ''; $sql = 'SELECT * FROM "tbl_invUnit" unit' . ' LEFT JOIN "employeeDB" emp ON emp."employeeID"=unit."updatedBy" ' . ' WHERE "styleId"=' . $_GET['styleId'] . ' order by "updatedAt" desc limit 1'; if (!($result = pg_query($connection, $sql))) { print("Failed location fetch Query: " . pg_last_error($connection)); exit; } $emp = pg_fetch_array($result); pg_free_result($result); //Get Location for a Unit if (isset($_GET['boxId']) && $_GET['boxId'] != 0) { $sql = ''; $sql = 'SELECT * FROM "tbl_invUnit" unit' . ' LEFT JOIN "locationDetails" details on details.id = unit."storageId"' . ' LEFT JOIN "tbl_invLocation" location on location."locationId" = CAST(details."locationId" as bigint)' . ' WHERE unit.id=' . $_GET['boxId']; if (!($result = pg_query($connection, $sql))) { print("Failed location fetch Query: " . pg_last_error($connection)); exit; } $location = pg_fetch_array($result); pg_free_result($result); $locationName = $location['name']; $storageType = $location['type']; $boxName = $location['identifier'] . '_' . $location[$storageType] . '_' . $location['box']; $rowName = $location['row']; $rackName = $location['rack']; $shelfName = $location['shelf']; } else { $locationName = 'All Location'; $boxName = 'All Box'; $storageType = 'allBox'; $rowName = 'All Row'; $rackName = 'All Rack'; $shelfName = 'All Shelf'; } //Get all Quantity For A unit $sql = ''; $sql = 'SELECT unit.*,quantity.*,details.*,location.identifier FROM "tbl_invUnit" unit '; $sql .= ' LEFT JOIN "tbl_invQuantity" quantity on unit.id = quantity."boxId" '; $sql .= ' LEFT JOIN "locationDetails" details on unit."storageId" = details.id'; $sql .= ' LEFT JOIN "tbl_invLocation" location on location."locationId"= CAST(details."locationId" as INT)'; $sql .= ' WHERE unit."styleId"=' . $_GET['styleId']; if (isset($_GET['boxId']) && $_GET['boxId'] != 0) { $sql .= ' and unit.id=' . $_GET['boxId']; } if (isset($_GET['colorId']) && $_GET['colorId'] != 0) { $sql .= ' and unit."colorId"=' . $_GET['colorId']; } else { $sql .= ' and unit."colorId"=' . $dataColor[0]['colorId']; } if (!($result = pg_query($connection, $sql))) { print("Failed location fetch Query: " . pg_last_error($connection)); exit; } while ($row2 = pg_fetch_array($result)) { $data[] = $row2; } pg_free_result($result); $dataQuantity = []; $dataToolTip = []; //echo $sql; //exit(); /*print '
';
    print_r($data);
    print '
'; exit();*/ foreach ($data as $key => $value) { $total = 0; if (isset($dataQuantity[$value['mainSizeId']][$value['optSizeId']])) { $total = $dataQuantity[$value['mainSizeId']][$value['optSizeId']] + $value['qty']; $dataQuantity[$value['mainSizeId']][$value['optSizeId']] = $total; if($value['qty'] > 0){ $link = $dataToolTip[$value['mainSizeId']][$value['optSizeId']].'
'.''.$value['identifier'].'_'.$value[$value['type']].'_'.$value['box'].' : '.$value['qty'].''; $dataToolTip[$value['mainSizeId']][$value['optSizeId']] = $link; $dataConveyor[$value['mainSizeId']][$value['optSizeId']] = $value['conveyor_slot']; } } else { $dataQuantity[$value['mainSizeId']][$value['optSizeId']] = $value['qty']; if($value['qty'] > 0){ $link = ''.$value['identifier'].'_'.$value[$value['type']].'_'.$value['box'].' : '.$value['qty'].''; $dataToolTip[$value['mainSizeId']][$value['optSizeId']] = $link ; } $dataConveyor[$value['mainSizeId']][$value['optSizeId']] = $value['conveyor_slot']; } } if (isset($_GET['boxId']) && $_GET['boxId'] != 0) { if(isset($_GET['colorId']) && $_GET['colorId'] != 0){ $colorId = $_GET['colorId']; } else { $colorId = $dataColor[0]['colorId']; } $sql = ''; $sql = 'SELECT unit.id as number,unit.box,unit.type,details.*,location.identifier FROM "tbl_invUnit" unit ' . ' LEFT JOIN "locationDetails" details ON details.id=unit."storageId" ' . 'LEFT JOIN "tbl_invLocation" location ON location."locationId"= CAST(details."locationId" as INT) ' . 'WHERE unit."styleId"=' . $_GET['styleId'] . ' and "colorId"='.$colorId.' and unit.id <>' . $_GET['boxId'] . ' and merged=0'; if (!($result = pg_query($connection, $sql))) { print("Failed location fetch Query: " . pg_last_error($connection)); exit; } while ($row2 = pg_fetch_array($result)) { $mergedLocation[] = $row2; } pg_free_result($result); } $sql = ''; $sql = 'SELECT * FROM "tbl_invLocation"'; if (!($result = pg_query($connection, $sql))) { print("Failed location fetch Query: " . pg_last_error($connection)); exit; } while ($row2 = pg_fetch_array($result)) { $locationChange[] = $row2; } pg_free_result($result); $stylebox1 = array(); foreach ($allUnit as $unit) { $stylebox1[$unit[0]] = $unit['box']; } natcasesort($stylebox1); } else { echo '

Please select a Style to view the Report

'; exit(); } ?>
Style:
Garment Type:
Client:
Gender:
Color:
Employee:
Date Entered:
Location:
Box#:
0) { ?>
Row:
Rack:
Shelf:
Row:
Rack:
Shelf:
'; foreach ($dataMainSizeId as $key => $value) { ; $element .= ''; } $element .= ''; $abcd =0; if (count($dataOptSizeId) > 0) { foreach ($dataOptSizeId as $key1 => $value1) { $element .= ''; $element .= ''; foreach ($dataMainSizeId as $key2 => $value2) { if (isset($dataQuantity[$key2][$key1]) && $dataQuantity[$key2][$key1] > 0) { $abcd++; $element .= ''; } else { $element .= ''; } } $element .= ''; } } else { $element .= ''; $element .= ''; foreach ($dataMainSizeId as $key2 => $value2) { if (isset($dataQuantity[$key2][0]) && $dataQuantity[$key2][0] > 0) { $element .= ''; } else { $element .= ''; } } $element .= ''; } echo $element; /*echo '
'; foreach ($dataMainSizeId as $key2 => $value2) { echo $dataQuantity[$key2][0] .' '.$dataToolTip[$key2][0]; } */ ?>
#' . $value . '
' . $value1 . ''; $element .= '

'.$dataToolTip[$key2][$key1].'

'; $element .= ''; $element .= ''; $element .= '
'; $element .= ''; $element .= ''; $element .= '
Qty'; $element .='

'.$dataToolTip[$key2][0].'

'; $element .= ''; $element .= ''; $element .= '
'; $element .= ''; $element .= ''; $element .= '