$worksheet = json_decode($_REQUEST['data'], true);
$hdnGrandTotal = number_format($worksheet['data']['mandatoryFields']['mand_hdnGrandTotal'], 2, ",", ".");
$hdnSubTotal = number_format($worksheet['data']['mandatoryFields']['mand_hdnSubTotal'], 2, ",", ".");
$params = array(
'id' => $worksheet['data']['id'],
'sostatus' => $worksheet['data']['newStatus'],
'subject' => $worksheet['data']['mandatoryFields']['mand_subject'],
'contact_id' => $worksheet['data']['mandatoryFields']['mand_contact_id'],
'account_id' => $worksheet['data']['mandatoryFields']['mand_account_id'],
'bill_street' => $worksheet['data']['mandatoryFields']['mand_bill_street'],
'ship_street' => $worksheet['data']['mandatoryFields']['mand_ship_street'],
'hdnGrandTotal' => $hdnGrandTotal,
'hdnSubTotal' => $hdnSubTotal,
'assigned_user_id' => $worksheet['data']['mandatoryFields']['mand_assigned_user_id']
);
// Add custom fields to params, if any
if (count($worksheet['data']['customFields']) > 0) {
foreach ($worksheet['data']['customFields'] as $cf_no => $value) {
$params[$cf_no] = $value;
}
}
$client->doInvoke('createWorkSheetHTML',
array( 'id' => $worksheet['data']['id'],
'autograph' => $worksheet['data']['signature'],
'lines' => json_encode($worksheet['data']['materials']),
'autogr_name' => $worksheet['data']['autogr_name'],
'times' => json_encode($worksheet['data']['times'])
),
'POST');
// Convert materials to a string
$materials = '';
foreach($worksheet['data']['materials'] as $material) {
$materials .= $material['qty'] . ' X ' . $material['desc'] . ', ';
}
$params['cf_968'] = $materials;
$r = $client->doUpdate('SalesOrder', $params);