DataTables warning: table id=transactions - Unknown field: transactions.date_received (index 0)

DataTables warning: table id=transactions - Unknown field: transactions.date_received (index 0)

misteammisteam Posts: 34Questions: 11Answers: 0
edited October 2019 in General

What' wromh with my code?

<?php
date_default_timezone_set("Asia/Manila");
// DataTables PHP library
include( "../php/DataTables.php" );
$date_from2 = $_POST['date_from2'];
$date_to2 = $_POST['date_to2'];
$users_id = $_POST['users_id'];
// $overall_stats = $_POST['overall_stats'];
$year = $_POST['year'];
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;

function logChange ( $db, $id) {

    $date = new DateTime(); 
    $date->modify("-1 days");
    // echo $date->format("Y-m-d H:i:s");

    $db->insert( 'transaction_history2', array(
        'user_id'           => $GLOBALS['users_id'],
        'values_log'        => $GLOBALS["overall_stats"],
        'transaction_id'    => $id,
        'date_log'          => $date->format("m-d-Y")
    ) );
}

/*
 * Example PHP implementation used for the join.html example
 */
Editor::inst( $db, 'transactions' )
->field(
    Field::inst( 'transactions.id' ),
    Field::inst( 'transactions.date_received' )->validator( 'Validate::dateFormat', array('empty' => false,'format' => 'm-d-Y')),
    Field::inst( 'transactions.time_received' )->validator( 'Validate::dateFormat', array('empty' => false,'format' => 'Hi')),

    Field::inst( 'transactions.vendor_id' )
    ->options( Options::inst()
        ->table( 'vendors' )
        ->value( 'id' )
        ->label( 'description' )
    ),
    Field::inst( 'vendors.description' ),
    Field::inst( 'transactions.soa_no' ),
    Field::inst( 'transactions.amount' ),
    Field::inst( 'transactions.sap_doc' ),
    Field::inst( 'transactions.truckers_no' ),
    Field::inst( 'transactions.dr' ),

    Field::inst( 'transactions.plant_id' )
    ->options( Options::inst()
        ->table( 'plant' )
        ->value( 'id' )
        ->label( 'description' )
    ),
    Field::inst( 'transactions.date_parked' ),
    Field::inst( 'transactions.posting_date' ),
    Field::inst( 'transactions.date_released' ),
    Field::inst( 'transactions.released_to' ),
    Field::inst( 'transactions.reason_return' ),
    Field::inst( 'transactions.received_from' ),
    Field::inst( 'transactions.department' ),
    Field::inst( 'transactions.rush' ),
    Field::inst( 'transactions.reversal_remarks' ),

    Field::inst( 'u1.last_name' ),
    Field::inst( 'u1.first_name' ),
    
    Field::inst( 'transactions.date_checked' ),

    Field::inst( 'transactions.transaction_type_id' )
    ->options( Options::inst()
        ->table( 'transaction_type' )
        ->value( 'id' )
        ->label( 'description' )
    ),

    Field::inst( 'u2.last_name' ),
    Field::inst( 'u2.first_name' ),

    Field::inst( 'transactions.date_encoded' ), 

    Field::inst( 'u3.last_name' ),
    Field::inst( 'u3.first_name' ),

    Field::inst( 'transactions.date_modified' ),
    
    Field::inst( 'transactions.status' ),
    Field::inst( 'transactions.year' )

)
->on( 'postEdit', function ($editor, $id, $row) {
    logChange( $editor->db(),$id);
} )
->on( 'postRemove', function ( $editor, $id, $row ) {
    logChange( $editor->db(),$id);
} )

->leftJoin( 'vendors', 'vendors.id', '=', 'transactions.vendor_id' )
->leftJoin( 'plant', 'plant.id', '=', 'transactions.plant_id' )
->leftJoin( 'users u1', 'u1.id', '=', 'transactions.checked_by' )
->leftJoin( 'users u2', 'u2.id', '=', 'transactions.encoded_by' )
->leftJoin( 'users u3', 'u3.id', '=', 'transactions.modified_by' )
->where( function ($q) {
    $q->where( 'transactions.is_deleted', 0, '=' );
    
    if($GLOBALS["date_from2"] != '' && $GLOBALS["date_from2"] != ''){
        $dt_from = date_create($GLOBALS["date_from2"]);
        $dt_to = date_create($GLOBALS["date_to2"]);
        $q->and_where('date_received', date_format($dt_from,'m-d-Y') ,'>=');
        $q->and_where('date_received', date_format($dt_to,'m-d-Y') ,'<=');
    }

    $q->where( 'transactions.year', $GLOBALS["year"], '=' );

})
->process($_POST)
->json();

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Replies

  • allanallan Posts: 52,525Questions: 1Answers: 8,020 Site admin

    Nothing immediately obvious. What is going wrong - are you getting a syntax error, is it not applying the condition, giving a database error, or something else? Its just about impossible to say what's wrong with the above code without knowing the symptoms I'm afraid!

    Thanks,
    Allan

Sign In or Register to comment.