<?php include('techsyn_header.php'); ?>
<!-- Main Content Container for side bar and body-->
<div class="main-container ace-save-state" id="main-container">
    <script type="text/javascript">
    try {
        ace.settings.loadState('main-container')
    } catch (e) {}
    </script>
    <?php include('techsyn_sidebar.php'); ?>

    <!--breadcrumb-->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="breadcrumbs ace-save-state" id="breadcrumbs">
                <ul class="breadcrumb">

                    <li class="#">Inventory Management</li>
                    <li class="active">APPROED PO</li>
                </ul>
            </div>
            <!-- End of breadcrumb -->

            <div class="page-content">

                <form name="f1" method="post" action="" id="flex_form_indent">
                    <div id="flex1" style="width:100%">
                    </div>
                    <input type="hidden" name="flex_indent_id" id="flex_indent_id" />
                </form>
                <form name="export_form" method="post" id="export_form" action="">

                    <input type="hidden" name="pdf_action" id="pdf_action" value="pdf_indent_pending.php" />
                    <input type="hidden" name="excel_action" id="excel_action" value="excel_indent_pending.php" />
                </form>
            </div>



        </div><!-- /.page-content -->
    </div>
</div><!-- /.main-content -->




<script type="text/javascript">
$(function() {
    var w = screen.width * .90;
    var h = 0;
    h = (window.innerHeight - ($("#navbar").height() + $(".breadcrumbs").height())) * .75;
    $("#flex1").flexigrid({
        url: 'approved_po_script.php',
        dataType: 'json',
        colModel: [{
                display: '',
                name: '',
                width: w * .05,
                sortable: false,
                align: 'left'
            },
            {
                display: 'Sr',
                name: 'count',
                width: w * .04,
                sortable: false,
                align: 'left'
            },
            {
                display: 'Indent Ref No',
                name: 'indent_ref_no',
                width: w * .10,
                sortable: true,
                align: 'left'
            },
            {
                display: 'POs Ref No',
                name: 'po_ref_no',
                width: w * .12,
                sortable: true,
                align: 'left'
            }, {
                display: 'Indent date',
                name: 'indent_date',
                width: w * .10,
                sortable: true,
                align: 'left'
            },
            {
                display: 'Total Price.',
                name: 'total_price',
                width: w * .15,
                sortable: true,
                align: 'left'
            },
            {
                display: 'Remarks',
                name: 'remarks',
                width: w * .25,
                sortable: true,
                align: 'left'
            },
            {
                display: 'Status',
                name: 'status',
                width: w * .15,
                sortable: true,
                align: 'left'
            },
            {
                display: 'Approval Remarks',
                name: 'approval_remarks',
                width: w * .25,
                sortable: true,
                align: 'left'
            },



        ],
        buttons: [


            {
                name: 'PDF',
                bclass: 'print',
                onpress: pdf
            },
            {
                separator: true
            },
            {
                name: 'Excel',
                bclass: 'print_excel',
                onpress: excel
            },
            {
                separator: true
            },


        ],
        searchitems: [



            {
                display: 'indent_date',
                name: 'indent_date'
            },


        ],
        sortname: "indent_id",
        sortorder: "desc",
        usepager: true, //pagination

        useRp: true,
        rp: 50, //records per page
        showTableToggleBtn: false, //toggle button for the whole table
        resizable: true,
        //width: w,
        height: h,
        singleSelect: true
    });
});

function pdf() {
    //window.open('pdf_manage_item.php');

    window.open('ajax_pdf.php', 'Indent List');
}

function excel() {
    window.open('ajax_excel.php', 'Indent List');
}

function open_indent_items_pdf(indent_id) {
    $("#flex_indent_id").val(indent_id);
    $("#flex_form_indent").attr('target', '_blank');
    $("#flex_form_indent").attr('method', 'POST');
    $("#flex_form_indent").attr('action', 'indent_pdf.php');
    $("#flex_form_indent").submit();
}

function open_po_items_pdf(indent_id) {
    $("#flex_indent_id").val(indent_id);
    $("#flex_form_indent").attr('target', '_blank');
    $("#flex_form_indent").attr('method', 'POST');
    $("#flex_form_indent").attr('action', 'po_pdf.php');
    $("#flex_form_indent").submit();
}


function delete_indent(indent_id, action) {
    if (action == "E") {
        $.ajax({
            url: 'delete_past_indent_rec.php',
            data: {
                indent_id: indent_id
            },
            type: 'POST',
            success: function(data) {
                if (JSON.parse(data) == "SUCCESS") {
                    BootstrapDialog.alert("Deleted Successfully");
                }
                $("#flex1").flexReload();
            },
            error: function(data) {
                BootstrapDialog.alert("Try Again");
            }
        })
    }
}


function open_item(appointmentId, appointment_type, dept_id, rowElement) {

    $.ajax({
        url: 'get_encode_data.php',
        type: "POST",
        data: {
            'id': appointmentId,
            'action': 'e'
        },
        dataType: 'json',
        success: function(data) {
            var app_id = data.id;
            // alert(app_id);
            $("#appointmentId").val("");
            $("#appointment_type").val("");
            $("#email_form").find("#ref_identifier").val(appointmentId);

            var to = dept_id;

            var emailContent = "";


            var app_root = '<?php echo getConfigKey('APP_ROOT') ?>';
            var to_list = "" + to + ",<?php echo getConfigKey('GENERAL_EMAIL_LIST_TO_INDENT') ?>";
            var link = "" + app_root + "/indent_pdf.php?flex_indent_id=" + appointmentId + '/';
            $("#email_form").find("#ref_type").val("INDENTS");
            $("#email_form").find("#to").val(to_list);
            $("#email_form").find("#cc").val('<?php echo getConfigKey('GENERAL_EMAIL_LIST_CC_INDENT') ?>');
            $("#email_form").find("#subject").val(
                '<?php echo getConfigKey('GENERAL_EMAIL_SUBJECT_INDENT') ?>');
            $("#email_form").find("#email_content").text(
                '<div style=\"style="text-transform: none; !important"\"><?php echo getConfigKey('GENERAL_EMAIL_TEXT_INDENT') ?></div>'
            );
            emailContent +=
                "<table class='table-bordered' width='100%'><thead><tr><th>Indent Ref. No.</th><th>Indent Date</th><th>Remarks</th><th>Status</th><th>Approval Remarks</th></tr><thead><tbody>";
            emailContent += "<tr><td>" + $(rowElement).parent().parent().parent()
                .children(
                    "td[abbr='indent_ref_no']").text() + "</td><td>" + $(rowElement).parent()
                .parent().parent().children("td[abbr='indent_date']").text() + "</td><td>" + $(
                    rowElement).parent().parent().parent().children("td[abbr='remarks']").text() +
                "</td><td>" + $(
                    rowElement).parent().parent().parent().children("td[abbr='status']").text() +
                "</td><td>" + $(rowElement).parent().parent().parent().children(
                    "td[abbr='approval_remarks']")
                .text() + "</td></tr>";
            emailContent += "</tbody></table>";
            emailContent += "<br><a href='" + link + "'>Items Details</a> ";
            $("#email_form").find("#email_content").html(emailContent);

            //   window.alert("{appointmentId}");
            var id = appointmentId;

            resizeChosen();
            jQuery(window).on('resize', resizeChosen);
            $('#modal-add-email').modal("show");
        },
        error: function(data) {
            BootstrapDialog.alert('Error In Pulling Id');
            return id;
        }

    });
}

function send_email() {
    var appointment_id;

    $("#message").val($("#email_form").find("#email_content").html());
    $.ajax({
        url: 'send_email.php',
        type: 'POST',
        data: $("#email_form").serialize(),
        success: function(data) {
            BootstrapDialog.alert('Mail send Successfully');
            $("#flex1").flexReload();
            return;
        },
        error: function(data) {
            BootstrapDialog.alert('Error in sending mail');
            return;
        }
    });
    $('.close').click();
}
</script>

<?php include('techsyn_footer.php'); 
include('form/send_mail.php');?>