Commit 156fcfb1 by Tatang

pay list

1 parent 7adac598
......@@ -41,6 +41,7 @@ api-produk-vendor-delete,/api/produk/vendor/{id}/delete,Delete Produk Vendor,1,0
api-payment-list,/api/payment/list,Test Api Payment,1,0
api-payment-act,/api/payment/{act}/act,Test Api Payment,1,0
api-payment-add,/api/payment/add,Add Api Payment,1,0
api-payment-edit,/api/payment/{id}/edit,Edit Api Payment,1,0
api-payment-delete,/api/payment/{id}/delete,Delete Api Payment,1,0
......
import colander
from datatables import ColumnDT
from deform import widget, Form, ValidationFailure
from opensipkd.base.views import DataTables
from pyramid.httpexceptions import HTTPFound
from pyramid.view import view_config
from sqlalchemy.orm import aliased
from . import BaseView
from ..models import (DBSession, PartnerPay, Partner)
from opensipkd.base.tools import format_json
from opensipkd.base.tools.db import column_concat
status_payment = (
(-1, '--Semua--'),
(0, 'Pending'),
(1, 'Sukses / Selesai'),
(2, 'Batal / Reversal'),
)
def form_validator(form, value):
pass
class ViewData(BaseView):
@view_config(route_name='api-payment-list',
permission="api-payment-list",
renderer='templates/payment/list.pt')
def view_list(self):
class ToolbarSchema(colander.Schema):
status = colander.SchemaNode(
colander.String(),
oid="status", widget=widget.SelectWidget(values=status_payment, css_class='form-toolbar')
)
toolbar = ToolbarSchema(Validator=form_validator)
toolbar.request = self.req
form = Form(schema=toolbar)
params = {
'form': form,
'status_payment': [s for k, s in status_payment if k > -1],
'columns': [
dict(title="ID"),
dict(title="No. Invoice"),
dict(title="Customer"),
dict(title="Vendor"),
dict(title="Amount"),
dict(title="Status"),
],
'column_data': [
dict(data="id", width="0px"),
dict(data="nomor", width="150px"),
dict(data="customer"),
dict(data="vendor"),
dict(data="amount", width="100px"),
dict(data="status", width="100px"),
],
'buttons': [
dict(id="btn_view", cls="btn btn btn-primary", title="View"),
dict(id="btn_close", cls="btn btn-danger", title="Tutup"),
],
'route': "/api/payment",
'scripts': """
$("#btn_close").click(function() {
window.location = '/api/merchant';
return false;
});
"""}
return dict(params=params)
@view_config(route_name='api-payment-act', renderer='json',
permission="api-payment-list"
)
def view_act(self):
request = self.req
url_dict = request.matchdict
act = url_dict['act']
if act == "grid":
status = -1
if 'status' in request.params:
status = int(request.params['status'])
vendor = aliased(Partner, name='vendor')
customer = aliased(Partner, name='customer')
columns = [
ColumnDT(PartnerPay.id, mData='id'),
ColumnDT(PartnerPay.cust_inv_no, mData='nomor'),
ColumnDT(
column_concat([
PartnerPay.inv_cust_nm,
' - (',
customer.nama,
')'
]),
mData='customer'
),
ColumnDT(vendor.nama, mData='vendor'),
ColumnDT(PartnerPay.amt_sell, mData='amount'),
ColumnDT(PartnerPay.status, mData='status'),
]
query = DBSession.query().select_from(PartnerPay)\
.join(vendor, vendor.id == PartnerPay.vendor_id)\
.join(customer, customer.id == PartnerPay.customer_id)
if status > -1:
query = query.filter(PartnerPay.status == status)
row_table = DataTables(request.GET, query, columns)
return row_table.output_result()
@view_config(route_name='api-payment-view',
permission="api-payment-list",
renderer='templates/payment/view.pt')
def view_detail(self):
request = self.req
url_dict = request.matchdict
view_id = url_dict['id']
data = PartnerPay.query_id(id=view_id).first()
params = dict(
form=None
)
if data:
customer = '{cust} - ({merc})'.format(cust=data.inv_cust_nm, merc=data.customer.nama)
form_list = (
('vend_inv_no', data.vend_inv_no or '', 'text'),
('cust_inv_no', data.cust_inv_no or '', 'text'),
# ('tx_id', data.tx_id or '', 'text'),
('vendor', data.vendor.nama, 'text'),
('produk', data.produk.nama, 'text'),
# ('id_pel', data.id_pel or '', 'text'),
('customer', customer, 'text'),
('cust_addr', data.inv_cust_addr or '', 'text'),
('cust_phone', data.inv_cust_phone or '', 'text'),
('cust_email', data.inv_cust_email or '', 'text'),
('cust_city', data.inv_cust_city or '', 'text'),
('cust_state', data.inv_cust_state or '', 'text'),
('cust_pos', data.inv_cust_pos or '', 'text'),
('cust_country', data.inv_cust_country or '', 'text'),
# ('inv_valid_date', data.description, 'text'),
# ('inv_valid_time', data.description, 'text'),
# ('inv_time_stamp', data.description, 'text'),
# ('inv_cust_va', data.description, 'text'),
#
# ('delivery_addr', data.description, 'text'),
# ('delivery_city', data.description, 'text'),
# ('delivery_country', data.description, 'text'),
# ('delivery_nm', data.description, 'text'),
# ('delivery_phone', data.description, 'text'),
# ('delivery_pos', data.description, 'text'),
# ('delivery_state', data.description, 'text'),
# ('delivery_email', data.description, 'text'),
# ('subtotal', data.subtotal, 'text'),
# ('discount', data.discount, 'text'),
# ('amt_sell', data.amt_sell, 'text'),
('inquiry', format_json(data.inquiry), 'area'),
('payment', format_json(data.payment), 'area'),
('advice', format_json(data.advice), 'area'),
('notify', format_json(data.notify), 'area'),
('cart', format_json(data.cart), 'area'),
# ('notes', data.notes, 'text'),
# ('description', data.description, 'text'),
# ('fee', data.description, 'text'),
# ('instmnt_mon', data.description, 'text'),
# ('instmnt_type', data.description, 'text'),
# ('recurr_opt', data.description, 'text'),
# ('m_ref_no', data.description, 'text'),
# ('notax_amt', data.description, 'text'),
# ('pay_valid_dt', data.description, 'text'),
# ('pay_valid_tm', data.description, 'text'),
#
# ('req_dt', data.description, 'text'),
# ('req_tm', data.description, 'text'),
#
# ('vat', data.description, 'text'),
# ('trans_dt', data.description, 'text'),
# ('trans_tm', data.description, 'text'),
# ('card_no', data.description, 'text'),
# ('callback_url', data.description, 'text'),
)
sm = colander.Schema()
values = {}
for f in form_list:
k = f[0]
v = f[1]
wg = f[2] == 'area' and widget.TextAreaWidget(style='height:120px') or\
widget.TextInputWidget(readonly=True)
sm.add(colander.SchemaNode(
colander.String(),
name=k,
oid=k,
widget=wg
))
values.update({k: v})
form = Form(sm)
form.render(values)
params['form'] = form
return dict(params=params)
......@@ -34,13 +34,13 @@
</a>
</li>
-->
<li>
<a href="${request._host}/api/payment/list">
<i class="fa fa-lg fa-fw fa-home"></i>
<span class="menu-item-parent">List Payment</span>
</a>
</li>
-->
<li>
<a href="${request._host}/api/merchant/register">
<i class="fa fa-lg fa-fw fa-home"></i>
......
<div metal:use-macro="load: ../base.pt">
<!-- content -->
<div metal:fill-slot="content">
<style type="text/css">
#content-payment-view {
max-height: 100vw;
overflow-y: auto;
}
</style>
<div id="tmp-toolbar">
<span tal:repeat="f params.form" tal:omit-tag="">
${structure:f.serialize()}
</span>
</div>
<div class="jarviswidget" style="border-top:1px solid #ccc!important">
<div role="content">
<table id="table1" class="table table-bordered table-hover table-condensed">
<thead>
<tr>
<th tal:repeat="f params.columns">${f.title}</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<!-- Modal -->
<div id="payment-view" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">
View Detail
<span style="margin-left: 10px" id="payment-view-title"></span>
</h4>
</div>
<div class="modal-body" id="content-payment-view">
&nbps;
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">OK</button>
</div>
</div>
</div>
</div>
</div>
<!-- end content -->
<script type="text/javascript" metal:fill-slot="scripts">
var mID;
var oTable;
var oTableUri = "${request._host}${params.route}"
var oTableUrl = oTableUri + "/grid/act";
function getDataUrl() {
var opt = $('select#status').val();
return oTableUrl + '?status=' + opt.toString();
}
function getViewUrl(vid) {
return oTableUri + "/" + vid.toString() + "/view";
}
$(document).ready(function() {
oTable = $('#table1').DataTable({
dom: '<"row"<"col-md-8"<"toolbar">l><"col-md-4"f>>rtip',
processing: true,
serverSide: true,
ajax: getDataUrl(),
stateSave: true,
//scrollCollapse: true,
//sort: true,
//info: false,
filter: true,
autoWidth: false,
paginate: true,
paginationType: "full_numbers",
lengthMenu: [
[10, 25, 50, 100],
[10, 25, 50, 100]
],
// columns: [
// {'data': 'id', 'width': '0px'},
// {'data': 'nomor', 'width': '150px'},
// {'data': 'customer'},
// {'data': 'vendor'},
// {'data': 'amount', 'width': '100px'},
// {'data': 'status', 'width': '100px',
// 'render': function(data, type, full, meta) {
// var st = ${params.status_payment};
// return st[data];
// }
// }
// ],
columns: ${params.column_data},
columnDefs: [{
searchable: false,
visible: false,
targets: [0]
}],
"language": {
"search": "Cari : ",
"paginate": {
"first": "Pertama ",
"last": "Akhir ",
"previous": "",
"next": "",
},
"lengthMenu": "Tampil _MENU_ baris "
},
});
var buttons=${params.buttons};
var tb_array=[];
tb_array.push('<div class="btn-group pull-left">');
for (i=0; i<buttons.length; i++){
tb_array.push('<button id="'+buttons[i].id+'" class="' +buttons[i].cls+
'" type="button">'+buttons[i].title+'</button>')
}
tb_array.push(' &nbsp;');
tb_array.push('</div>');
var tb = tb_array.join(' ');
$("div.toolbar").html(tb)
.attr('style', 'display:block; float: left; margin-bottom:6px; line-height:16px;');
$('select.form-toolbar').appendTo($("div.toolbar"));
$('tmp-toolbar').hide();
//events
$('#table1 tbody').on('click', 'tr', function() {
if ($(this).hasClass('selected')) {
$(this).removeClass('selected');
} else {
var aData = oTable.row(this).data();
oTable.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
mID = aData.id;
// console.log(mID);
oTable.$('tr.row_selected').removeClass('row_selected');
$(this).addClass('row_selected');
}
});
${params.scripts}
$('#btn_view').click(function() {
if (mID) {
//window.location = oTableUri + '/' + mID + '/view';
$('#payment-view').modal('show');
} else {
$.SmartMessageBox({
title : "View",
content : "Pilih Baris yang akan di lihat...",
buttons : '[Oke]'
});
}
});
$("#payment-view").on('show.bs.modal', function(){
var content = '';
var view_container = $('#content-payment-view');
view_container.empty();
if (mID) {
var vUrl = getViewUrl(mID);
view_container.load(vUrl, function() {
$('textarea').attr('readonly', true);
});
}
});
$('select#status').on('change', function() {
mID = 0;
oTable.ajax.url(getDataUrl()).load();
});
});
</script>
</div>
<div tal:condition="params.form" tal:omit-tag="">
<div class="form-horizontal">
<div tal:repeat="f params.form" class="row">
<div class="form-group">
<label for="${f.oid}" class="control-label col-md-3" id="req-${f.oid}">
${f.title}
</label>
<div class="col-md-9">
${structure:f.serialize()}
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!