Hi paramvir
Thanks to your sincere help, the part of saving the comment data in the DB was successful.
I really appreciate it.
I have a problem that needs to be addressed.
As shown in the attached image, there are two buttons.
When saving daily production data, I have to press button B,
and it is inconvenient to have to press button C to save the comment data.
But I made this into one button
When the Save button (B) is clicked,
I want to make the daily production data and daily comment data stored in the DB at the same time.
The program source is as below, but I would appreciate it if you could let me how.
1) Client program
toolbar: {
cls: 'pq-toolbar-export',
items: [
{ // 1) Button B
type: 'button',
icon: 'ui-icon-disk',
label: 'Save',
cls: 'changes',
listener: saveChanges,
options: { disabled: true },
},
{ // 2) Button C
type: 'button',
icon: 'ui-icon-disk',
label: 'Save comments',
cls: 'changes',
listener: function () {
var grid = this;
var arr = this.pageData().map(function(rd){
return {
id: rd.id, //id of the record.
pq_cellattr: JSON.stringify( rd.pq_cellattr),
pq_cellstyle: JSON.stringify( rd.pq_cellstyle )
}
});
//post comments array to server.
$.ajax({
url: 'product_plan_save.php',
data: {pq_meta: arr},
success: function (changes){
debugger;
grid.history({ method: 'reset' });
},
})
},
options: { disabled: true },
},
2) Server side program
//update single record in db.
function updateSingle($pdo, $r)
{
// 1) Update merged field
if($r['cd_kind'] == 0){
$query = "update pp2_month_new set qty_worker=?, eff_product=?, cycle_time=?, qty_not_ot=?, qty_ot=? ";
$query .= "where cd_group = ?";
$stmt = $pdo->prepare($query);
$result = $stmt->execute(array($r['qty_worker'], $r['eff_product'], $r['cycle_time'], $r['qty_not_ot'], $r['qty_ot'], $r['cd_group']));
if($result == false) {
throw new Exception(print_r($stmt->errorInfo(), 1).PHP_EOL.$query);
}
}
// 2) Update day, night, shipment, etc, stock
$total_day = date('t', strtotime($r['mt_product']));
$query = "update pp2_month_new set ";
for($j=1; $j<=$total_day; $j++){
$query .= "qty$j = ?, ";
}
$query = substr($query, 0, -2);
$query .= " where id = ?";
$stmt = $pdo->prepare($query);
$result = $stmt->execute(array(
$r['qty1'], $r['qty2'], $r['qty3'], $r['qty4'], $r['qty5'], $r['qty6'], $r['qty7'], $r['qty8'], $r['qty9'], $r['qty10'],
$r['qty11'], $r['qty12'], $r['qty13'], $r['qty14'], $r['qty15'], $r['qty16'], $r['qty17'], $r['qty18'], $r['qty19'], $r['qty20'],
$r['qty21'], $r['qty22'], $r['qty23'], $r['qty24'], $r['qty25'], $r['qty26'], $r['qty27'], $r['qty28'], $r['qty29'], $r['qty30'], $r['qty31'],
$r['id']));
if($result == false) {
throw new Exception(print_r($stmt->errorInfo(), 1).PHP_EOL.$query);
}
}
//Update comment data in db.
function updateComments($pdo)
{
$pq_meta = $_GET['pq_meta'];
foreach ($pq_meta as $meta){
$query = "update pp2_month_new set pq_cellattr = ? where id = ?";
$stmt = $pdo->prepare($query);
$result = $stmt->execute(array($meta['pq_cellattr'], $meta['id']));
if($result == false) {
throw new Exception(print_r($stmt->errorInfo(), 1).PHP_EOL.$query);
}
}
}
function updateList($updateList)
{
$pdo = getDBH();
foreach ($updateList as $key => $val){
updateSingle($pdo, $val);
}
}
if( isset($_GET["pq_update"])){ // Update
updateSingle(getDBH(), $_GET);
$response = "{\"result\": \"success\"}";
}
elseif( isset($_GET["pq_meta"])){ // Update comment data
updateComments(getDBH());
$response = "{\"result\": \"success\"}";
}
elseif( isset($_GET["pq_batch"])){ // Batch
$dlist = $_POST['list'];
if(isset($dlist["updateList"])){
updateList($dlist["updateList"]);
}
$response = json_encode($dlist);
}