<?php
include("../../packages/require.php");
include("controller/controller_detail.php");
$curpage = "po";
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title><?=$title['po'];?></title>
    <?php include($global['root']."packages/head.php");?>
    <style type="text/css">
        .activity-wrap {
            height: 270px;
            overflow-y: auto;
        }
    </style>
</head>
<body class="<?=$global['body-css'];?>">
    <div class="wrapper">

        <?php include($global['root']."section/header.php");?>

        <?php include($global['root']."section/sidebar.php");?>

        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                Module Purchase Order
                <small>Track all your po here</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="<?=$path['dashboard'];?>"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active">Purchase Order</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <!-- Default box -->
            <div class="box">
                <div class="box-header with-border">
                    <div class="row">
                        <div class="col-sm-8">
                            <h3 class="box-title full-xs xs-down10">
                                Preview Purchase Order (<?=correctDisplay($data[0]['po_id']);?>)
                                <?php if($data[0]['po_status'] == 'open'){ ?>
                                <span class="label label-info">Open</span>
                                <?php } else if($data[0]['po_status'] == 'progress'){ ?>
                                <span class="label label-warning">In Progress</span>
                                <?php } else if($data[0]['po_status'] == 'prepared'){ ?>
                                <span class="label label-primary">Prepared</span>
                                <?php } else if($data[0]['po_status'] == 'complete'){ ?>
                                <span class="label label-success">Completed</span>
                                <?php } else { ?>
                                <span class="label label-danger">Canceled</span>
                                <?php } ?>
                            </h3>
                        </div>
                        <div class="col-sm-4">
                            <div class="text-right">
                                <?php if($acsp_invoice == 1){ ?>
                                <?php if($data[0]['po_status'] != 'open' && $data[0]['po_status'] != 'prepared' && $data[0]['po_status'] != 'cancel'){ ?>
                                <a href="#modal-invoice" data-toggle="modal" data-target="#modal-invoice" class="btn btn-primary">
                                    <i class="fa fa-plus"></i> Update Invoice No.
                                </a>
                                <?php } ?>
                                <?php } ?>
                                <!-- <a href="<?=$path['po'];?>print-view.php?po=<?=$po_id;?>" target="_blank" class="btn bg-purple">
                                    <i class="fa fa-print"></i> Print Purchase Order
                                </a> -->
                            </div>
                        </div>
                    </div>
                </div>
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a href="<?=$path['po-detail'].$po_id.'/';?>">Preview Purchase Order</a>
                        </li>
                        <?php if($acsp_edit == 1){ ?>
                        <?php if($data[0]['po_status'] == 'open'){ ?>
                        <li>
                            <a href="<?=$path['po-edit'].$po_id.'/';?>">Edit Purchase Order</a>
                        </li>
                        <?php } ?>
                        <?php } ?>
                        <?php if($acsp_viewact == 1){ ?>
                        <li>
                            <a href="<?=$path['po-activity'].$po_id.'/';?>">Activity</a>
                        </li>
                        <?php } ?>
                        <?php if($acsp_document == 1){ ?>
                        <?php if($data[0]['po_status'] != 'open' && $data[0]['po_status'] != 'prepared' && $data[0]['po_status'] != 'cancel'){ ?>
                        <li>
                            <a href="<?=$path['po-document'].$po_id.'/';?>">Document</a>
                        </li>
                        <?php } ?>
                        <?php } ?>
                    </ul>
                </div>
                <div class="box-body">
                    <div class="row">
                        <div class="col-sm-6">
                            <div class="box-head">
                                Purchase Order Info
                            </div>
                            <div class="box-card xs-down10">
                                <strong>Purchase Order ID : <?=correctDisplay($data[0]['po_id']);?></strong><br/>
                                <strong>Purchase Order No : <?=correctDisplay($data[0]['po_order_num']);?></strong><br/>
                                <?php if($data[0]['po_invoice'] != NULL && $data[0]['po_invoice'] != ""){ ?>
                                <strong>Invoice No : <?=correctDisplay($data[0]['po_invoice']);?></strong><br/>
                                <?php } ?>
                                Document Date : <?=date("d F Y", strtotime($data[0]['po_date']));?><br/>
                                PIC : <?=correctDisplay($data[0]['admin_name']);?><br/>
                                Region : <?=correctDisplay($data[0]['region_title']);?>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="box-head">
                                Client Info
                            </div>
                            <div class="box-card">
                                <?php if($data[0]['client_name'] != ""){ ?>
                                <strong><?=correctDisplay($data[0]['client_name']);?></strong><br/>
                                <?php } ?>
                                <?php if($data[0]['po_subclient'] != ""){ ?>
                                <strong>Sub Client : <?=correctDisplay($data[0]['po_subclient']);?></strong><br/>
                                <?php } ?>
                                <?php if($data[0]['admin_client'] != "" && $data[0]['admin_client'] != NULL){ ?>
                                <strong>PIC : <?=correctDisplay($data[0]['admin_client']);?></strong><br/>
                                <?php } ?>
                                <?php if($data[0]['client_email'] != ""){ ?>
                                Email : <?=correctDisplay($data[0]['client_email']);?><br/>
                                <?php } ?>
                                <?php if($data[0]['client_phone'] != ""){ ?>
                                Phone Number : <?=correctDisplay($data[0]['client_phone']);?><br/>
                                <?php } ?>
                                <?php if($data[0]['client_address'] != ""){ ?>
                                Address : <?=correctDisplay($data[0]['client_address']);?><br/>
                                <?php } ?>
                            </div>
                        </div>
                    </div>

                    <?php if(is_array($items)){ ?>
                    <div class="order-item">
                        <div class="table-responsive table-click">
                            <table class="table table-bordered table-middle">
                                <thead>
                                    <tr>
                                        <th class="text-center">No</th>
                                        <th class="text-center">Description</th>
                                        <th class="text-center">Product</th>
                                        <th class="text-center">Qty</th>
                                        <th class="text-center">Unit</th>
                                        <?php if($acsp_hide_amount != 1){ ?>
                                        <th class="text-center">Price</th>
                                        <?php } ?>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $num=1;foreach($items as $item){ ?>
                                    <tr>
                                        <td class='text-center'><?=$num;?></td>
                                        <td class='text-center'><?=correctDisplay($item['atpo_desc']);?></td>
                                        <td class='text-center'><?=correctDisplay($item['atpo_product']);?></td>
                                        <td class='text-center'><?=$item['atpo_qty'];?></td>
                                        <td class='text-center'><?=$item['atpo_unit'];?></td>
                                        <?php if($acsp_hide_amount != 1){ ?>
                                        <td class='text-right'><?=convert_idr($item['atpo_price']);?></td>
                                        <?php } ?>
                                    </tr>
                                    <?php $num++;} ?>
                                </tbody>
                                <?php if($acsp_hide_amount != 1){ ?>
                                <tfooter>
                                    <tr>
                                        <td colspan="5" class="text-right bold">Subtotal</td>
                                        <td class="text-right bold txt-subtotal"><?=convert_idr($data[0]['po_subtotal']);?></td>
                                    </tr>
                                    <tr>
                                        <td colspan="5" class="text-right bold">PPN (<span id="tax-num"><?=$data[0]['po_ppn'];?></span>%)</td>
                                        <td class="text-right bold txt-ppnprice"><?=convert_idr($data[0]['po_ppn_amount']);?></td>
                                    </tr>
                                    <tr>
                                        <td colspan="5" class="text-right bold">Total</td>
                                        <td class="text-right bold txt-total"><?=convert_idr($data[0]['po_total']);?></td>
                                    </tr>
                                </tfooter>
                                <?php } ?>
                            </table>
                        </div>
                    </div>
                    <?php } ?>
                </div>
                <input type="hidden" id="redir-url" value="<?=$path['po-detail'].$po_id.'/';?>">
                <input type="hidden" id="input-pageurl" value="<?=$path['po-detail'];?>">
                <input type="hidden" id="po-id" value="<?=$po_id;?>">
                <div class="box-header" style="border-top: solid 1px #dddddd;border-bottom: solid 1px #dddddd;">
                    <div class="row">
                        <div class="col-sm-6">
                            <h3 class="box-title" style="margin-top: 6px;">
                                Notes
                            </h3>
                        </div>
                        <?php if($acsp_create_notes == 1){ ?>
                        <div class="col-sm-6">
                            <div class="text-right">
                                <a href="#modalPONotes" class="btn bg-fuchsia" data-toggle="modal" data-target="#modalPONotes">
                                    <i class="fa fa-comment-o"></i> Purchase Order Notes
                                </a>
                            </div>
                        </div>
                        <?php } ?>   
                    </div>
                </div>
                <?php if($data[0]['po_notes'] != ""){ ?>
                <div class="box-body">
                    <div class="activity-wrap">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="box-card">
                                    <?=correctDisplay($data[0]['po_notes']);?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <?php } ?>    
                <?php if($acsp_viewact == 1){ ?>
                <?php if(is_array($activitys)){ ?>
                <div class="box-header" style="border-top: solid 1px #dddddd;border-bottom: solid 1px #dddddd;">
                    <div class="row">
                        <div class="col-sm-6">
                            <h3 class="box-title" style="margin-top: 6px;">
                                List Activity
                            </h3>
                        </div>
                        <div class="col-sm-6">
                            <div class="text-right">
                                <?php if($acsp_createact == 1){ ?>
                                <a href="#modalNotes" class="btn btn-primary bg-purple" data-toggle="modal" data-target="#modalNotes">
                                    <i class="fa fa-comment-o"></i> Activity Notes
                                </a>
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <div class="activity-wrap">
                        <div class="row">
                            <div class="col-md-12">
                                <ul class="timeline">
                                    <?php foreach($activitys as $act){ ?>
                                    <li class="time-label">
                                        <span class="bg-red">
                                            <?=date("d F Y", strtotime($act['activity_create_date']));?>
                                        </span>
                                    </li>
                                    <?php if(is_array($act['po'])){ foreach($act['po'] as $ship){ ?>
                                    <li>
                                        <?php if($ship['activity_type'] == "complete"){ ?>
                                        <i class="fa fa-check bg-green"></i>
                                        <?php } else if($ship['activity_type'] == "prepared"){ ?>
                                        <i class="fa fa-archive bg-purple"></i>
                                        <?php } else if($ship['activity_type'] == "progress"){ ?>
                                        <i class="fa fa-spinner bg-orange"></i>
                                        <?php } else if($ship['activity_type'] == "open"){ ?>
                                        <i class="fa fa-book bg-red"></i>
                                        <?php } else if($ship['activity_type'] == "cancel"){ ?>
                                        <i class="fa fa-times bg-red"></i>
                                        <?php } else if($ship['activity_type'] == "quarantine"){ ?>
                                        <i class="fa fa-bug bg-yellow"></i>
                                        <?php } else if($ship['activity_type'] == "edit"){ ?>
                                        <i class="fa fa-edit bg-blue"></i>
                                        <?php } else if($ship['activity_type'] == "notes"){ ?>
                                        <i class="fa fa-comments-o bg-aqua"></i>
                                        <?php } else if($ship['activity_type'] == "add"){ ?>
                                        <i class="fa fa-plus bg-green"></i>
                                        <?php } else if($ship['activity_type'] == "update"){ ?>
                                        <i class="fa fa-pencil bg-maroon"></i>
                                        <?php } else if($ship['activity_type'] == "delete"){ ?>
                                        <i class="fa fa-trash bg-red"></i>
                                        <?php } else if($ship['activity_type'] == "print_ship"){ ?>
                                        <i class="fa fa-print bg-blue"></i>
                                        <?php } else if($ship['activity_type'] == "upload"){ ?>
                                        <i class="fa fa-upload bg-blue"></i>
                                        <?php } else if($ship['activity_type'] == "paid"){ ?>
                                        <i class="fa fa-money bg-green"></i>
                                        <?php } else if($ship['activity_type'] == "notpaid"){ ?>
                                        <i class="fa fa-money bg-red"></i>
                                        <?php } else if($ship['activity_type'] == "invoice"){ ?>
                                        <i class="fa fa-sticky-note bg-green"></i>
                                        <?php } ?>
                                        <div class="timeline-item">
                                            <span class="time">
                                                <i class="fa fa-clock-o"></i> <?=date("h:i:s", strtotime($ship['activity_create_date']));?>
                                            </span>
                                            <h3 class="timeline-header no-border">
                                                <a href="#"><?=ucfirst($ship['activity_ref_name']);?></a>
                                            </h3>
                                            <div class="timeline-body">
                                                <?=correctDisplay($ship['activity_notes']);?>
                                            </div>
                                        </div>
                                    </li>
                                    <?php } } ?>
                                    <?php } ?>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
                <?php } ?>
                <?php } ?>
                <div class="box-footer clearfix">
                    <div class="row">
                        <div class="col-sm-4 col-xs-6">
                            <div class="text-left">
                                <a href="<?=$path['po'];?>" class="btn btn-default full-xs xs-down10">
                                    <i class="fa fa-arrow-left"></i> Back
                                </a>
                            </div>
                        </div>
                        <div class="col-sm-8 col-xs-6">
                            <div class="text-right">
                                <?php if($acsp_prepared == 1){ ?>
                                <?php if($data[0]['po_status'] == 'open'){ ?>
                                <a href="javascript:void(0)" onclick="confirmStatusChange('prepared');" class="btn btn-primary full-xs xs-down10">
                                    <i class="fa fa-archive"></i> Prepared
                                </a>
                                <?php } ?>
                                <?php } ?>
                                <?php if($acsp_progress == 1){ ?>
                                <?php if($data[0]['po_status'] == 'prepared'){ ?>
                                <a href="javascript:void(0);" onclick="confirmStatusChange('progress');" class="btn bg-aqua full-xs xs-down10">
                                    <i class="fa fa-briefcase"></i> In Progress
                                </a>
                                <?php } ?>
                                <?php } ?>
                                <?php if($acsp_complete == 1){ ?>
                                <?php if($data[0]['po_status'] == 'progress'){ ?>
                                <a href="javascript:void(0);" onclick="confirmStatusChange('complete');" class="btn btn-success full-xs xs-down10">
                                    <i class="fa fa-check"></i> Complete
                                </a>
                                <?php } ?>
                                <?php } ?>
                                <?php if($acsp_cancel == 1){ ?>
                                <?php if($data[0]['po_status'] != 'cancel'){ ?>
                                <a href="javascript:void(0);" class="btn btn-danger full-xs xs-down10" onclick="confirmCancel()">
                                    <i class="fa fa-times"></i> Cancel PO
                                </a>
                                <?php } ?>
                                <?php } ?>
                                <?php if($acsp_delete == 1){ ?>
                                <?php if($data[0]['po_status'] == 'cancel'){ ?>
                                <a href="javascript:void(0);" class="btn btn-danger full-xs xs-down10" onclick="confirmDelete()">
                                    <i class="fa fa-trash"></i> Delete
                                </a>
                                <?php } ?>
                                <?php } ?>
                                <?php if($acsp_paid == 1){ ?>
                                <?php if($data[0]['po_status'] == 'complete'){ ?>
                                <?php if($data[0]['po_paid'] == 'no'){ ?>
                                <a href="javascript:void(0);" class="btn bg-green full-xs xs-down10" onclick="confirmPaid('yes')">
                                    <i class="fa fa-money"></i> Set as Paid
                                </a>
                                <?php } else { ?>
                                <a href="javascript:void(0);" class="btn bg-orange full-xs xs-down10" onclick="confirmPaid('no')">
                                    <i class="fa fa-money"></i> Set as Not Paid
                                </a>
                                <?php } ?>
                                <?php } ?>
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->

<?php include($global['root']."section/footer.php");?>

</div>
<!-- ./wrapper -->
<div id="modal-invoice" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog">
    <div class="modal-dialog mde-dialog modal-sm" role="document">
        <div class="modal-content mde-content">
            <div class="modal-header mde-header">
                <h4 class="modal-title mde-title">Update Invoice No.</h4>
            </div>
            <form id="form-insert" name="form-insert" action="<?=$path['po-detail'];?>?action=invoice" enctype="multipart/form-data" method="post">
                <div class="modal-body mde-body">
                    <div class="form-group" style="width: 500px;">
                        <label for="input-invoice">Invoice No. *</label>
                        <input type="text" class="form-control" name="invoice" id="input-invoice" placeholder="Invoice No" value="<?=$data[0]['po_invoice'];?>" >
                        <div id="error-invoice" class="error-text"></div>
                    </div>
                </div>
                <div class="modal-footer mde-footer">
                    <div class="row">
                        <div class="col-sm-6 col-xs-6">
                            <div class="text-left">
                                <a href="javascript:void(0);" data-dismiss="modal" class="btn btn-default">
                                    <i class="fa fa-arrow-left"></i> Close
                                </a>
                            </div>
                        </div>
                        <div class="col-sm-6 col-xs-6">
                            <div class="text-right">
                                <div class="btn-group">
                                    <input type="hidden" name="po_id" value="<?=$po_id;?>">
                                    <button type="submit" id="btn-submit" class="btn btn-success">
                                        <i class="fa fa-save"></i> Save Data
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<div id="modalPONotes" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog madd-dialog" role="document">
        <div class="modal-content madd-content">
            <div class="modal-header madd-header" style="background-color: #f012be !important">
                Purchase Order Notes
            </div>
            <form id="form-create" action="<?=$path['po-detail'].'?action=ponotes';?>" enctype="multipart/form-data" method="post" onsubmit="return validateFormPONotes();">
                <div class="modal-body madd-body">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label for="input-note">Notes </label>
                                <textarea class="form-control" name="ponote" id="input-ponote" placeholder="Notes" rows="5" ><?=correctDisplay($data[0]['po_notes']);?></textarea>
                                <div id="error-note" class="error-text"></div>
                                <input type="hidden" name="po_id" value="<?=$po_id;?>">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer madd-footer">
                    <div class="row">
                        <div class="col-sm-6 col-xs-6">
                            <div class="text-left">
                                <a href="#" data-dismiss="modal" class="btn btn-default">
                                <i class="fa fa-arrow-left"></i> Cancel
                                </a>
                            </div>
                        </div>
                        <div class="col-sm-6 col-xs-6">
                            <div class="text-right">
                                <button id="btn-savenote" class="btn btn-success" type="submit">
                                    <i class="fa fa-save"></i> Save Notes
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<div id="modalNotes" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog madd-dialog" role="document">
        <div class="modal-content madd-content">
            <div class="modal-header madd-header">
                Leave Activity Notes
            </div>
            <form id="form-create" action="<?=$path['po-detail'].'?action=notes';?>" enctype="multipart/form-data" method="post" onsubmit="return validateFormNotes();">
                <div class="modal-body madd-body">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label for="input-note">Notes </label>
                                <textarea class="form-control" name="note" id="input-note" placeholder="Notes" rows="5" ></textarea>
                                <div id="error-note" class="error-text"></div>
                                <input type="hidden" name="po_id" value="<?=$po_id;?>">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer madd-footer">
                    <div class="row">
                        <div class="col-sm-6 col-xs-6">
                            <div class="text-left">
                                <a href="#" data-dismiss="modal" class="btn btn-default">
                                <i class="fa fa-arrow-left"></i> Cancel
                                </a>
                            </div>
                        </div>
                        <div class="col-sm-6 col-xs-6">
                            <div class="text-right">
                                <button id="btn-savenote" class="btn btn-success" type="submit">
                                    <i class="fa fa-save"></i> Save Notes
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<?php include($global['root']."packages/footer.php");?>
<script type="text/javascript">
    $(document).ready(function() {
        <?php if(is_array($vmessage)){ ?>
        <?php $c=0; foreach($vmessage as $vm){ if($c > 0){ $time =  5000 + ($c*1000); } else { $time = 5000; } ?>
            var alertText = "<?=$vm;?>";
            <?php if($valert[$c] != "success"){ ?>
            errorAlertTimer(alertText,<?=$time;?>);// error alert
            <?php } else { ?>
            successAlertTimer(alertText,<?=$time;?>);// success alert
            <?php } ?>
        <?php $c++;} ?>
        <?php } ?>
    });
    $(function () {
      $('[data-toggle="tooltip"]').tooltip()
    })
</script>
<script src="<?=$global['absolute-url'];?>asset/plugins/scanner-barcode/jquery.scannerdetection.js"></script>
<script src="<?=$global['absolute-url'];?>module/po/js/detail.js?<?=mt_rand(10,1000);?>"></script>
</body>
</html>