add hidden account support add delete/payout buttons to carts add backend product sales with pdf export add frontend product sales with pdf export add frontend ticket sales with pdf export
269 lines
6.9 KiB
JavaScript
269 lines
6.9 KiB
JavaScript
function TicketSell(o){
|
|
|
|
/**reference for the instance*/
|
|
var app = this;
|
|
|
|
this.defaults = {
|
|
default_type: 0,
|
|
selected_type: 1,
|
|
time_unit_day : 10,
|
|
time_unit_month : 20,
|
|
time_unit_month_reference : 30,
|
|
/**id of filter text*/
|
|
types: [{
|
|
name :'Bérlet',
|
|
id_ticket_type: 0,
|
|
max_usage_count:0,
|
|
time_unit_type:1,
|
|
time_unit_count:1,
|
|
id_account:0,
|
|
price_brutto:1000,
|
|
},
|
|
],
|
|
selector_type: '#ticketcreate-id_ticket_type',
|
|
selector_start: '#ticketcreate-start',
|
|
selector_end: '#ticketcreate-end',
|
|
selector_account: '#ticketcreate-id_account',
|
|
selector_price: '#ticketcreate-price_brutto',
|
|
selector_max_usage_count: '#ticketcreate-max_usage_count',
|
|
date_format_moment: 'YYYY.MM.DD',
|
|
ticket_type: null,
|
|
start_date: null,
|
|
end_date: null,
|
|
max_usage_count: null,
|
|
id_account: null,
|
|
price: null,
|
|
clear_cart_url: '',
|
|
cart_paid_message: 'Tételek fizetve',
|
|
user_cart: [],
|
|
customer_cart: [],
|
|
/**selector for customer cart container*/
|
|
selector_customer_cart: '.customer-cart',
|
|
selector_user_cart: '.user-cart',
|
|
selector_btn_pay_customer_cart: '#btn_pay_customer_cart',
|
|
selector_btn_pay_user_cart: '#btn_pay_user_cart',
|
|
/**mark list paid url*/
|
|
url_pay_customer_card: '-',
|
|
url_pay_user_cart: '',
|
|
url_delete_transaction: '',
|
|
url_pay_transaction: '',
|
|
|
|
};
|
|
|
|
init();
|
|
|
|
function init(){
|
|
$.extend(app.defaults, o );
|
|
addBehaviourTypeChangedListener();
|
|
useDefaults();
|
|
createCarts();
|
|
addPayoutButtons();
|
|
addSellButtons();
|
|
// addBehaviourBtnCartPaid();
|
|
}
|
|
|
|
function useDefaults(){
|
|
if ( app.defaults.selected_type > 0){
|
|
$(app.defaults.selector_type).val( app.defaults.selected_type );
|
|
typeChanged();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
// carts
|
|
////////////////////////////////////////
|
|
|
|
/**
|
|
* payout out user or customer cart
|
|
* */
|
|
function addPayoutButtons(){
|
|
addBehaviourPayoutUserCart();
|
|
addBehaviourPayoutCustomerCart();
|
|
}
|
|
|
|
/**
|
|
* display user and customer cart on page load
|
|
* */
|
|
function createCarts(){
|
|
createUserCartTable();
|
|
createCustomerCartTable();
|
|
}
|
|
|
|
function createUserCartTable(){
|
|
$(app.defaults.selector_user_cart).transferList({
|
|
'transfers' : app.defaults.user_cart,
|
|
'url_delete' : app.defaults.url_delete_transaction,
|
|
'url_pay' : app.defaults.url_pay_transaction,
|
|
});
|
|
}
|
|
function createCustomerCartTable(){
|
|
$(app.defaults.selector_customer_cart).transferList({
|
|
'transfers' : app.defaults.customer_cart,
|
|
'url_delete' : app.defaults.url_delete_transaction,
|
|
'url_pay' : app.defaults.url_pay_transaction,
|
|
});
|
|
}
|
|
|
|
function addSellButtons(){
|
|
addBehaviourBtnSellAndAppendToUserCart();
|
|
addBehaviourBtnAddToCustomerCart();
|
|
addBehaviourBtnSell();
|
|
}
|
|
|
|
function addBehaviourBtnSellAndAppendToUserCart(){
|
|
$('#btn_add_to_user_cart').on('click',submitAddTicketToUserCart);
|
|
}
|
|
|
|
function addBehaviourBtnAddToCustomerCart(){
|
|
$('#btn_add_to_customer_cart').on('click',submitAddTicketToCustomerCart);
|
|
}
|
|
|
|
function submitSell(){
|
|
$('#ticketcreate-cart').val('');
|
|
$('#ticket_form').submit();
|
|
}
|
|
function submitAddTicketToUserCart(){
|
|
$('#ticketcreate-cart').val('user');
|
|
$('#ticket_form').submit();
|
|
}
|
|
|
|
function submitAddTicketToCustomerCart(){
|
|
$('#ticketcreate-cart').val('customer');
|
|
$('#ticket_form').submit();
|
|
}
|
|
|
|
function addBehaviourBtnSell(){
|
|
$('#btn_sell').on('click',submitSell);
|
|
}
|
|
|
|
function addBehaviourPayoutUserCart( ){
|
|
// $( app.defaults.selector_btn_pay_user_cart ).on('click',function(){
|
|
//
|
|
// $.ajax({
|
|
// url: app.defaults.url_pay_user_cart,
|
|
// type: 'post',
|
|
// data: {},
|
|
// success: function (response) {
|
|
// if ( response.code == 'success'){
|
|
// app.defaults.user_cart = response.transfers;
|
|
// refreshUserCart();
|
|
// $.notify(app.defaults.message_paid, { 'type' : 'success' });
|
|
// }
|
|
// }
|
|
// }
|
|
// );
|
|
// });
|
|
}
|
|
function addBehaviourPayoutCustomerCart( ){
|
|
// $( app.defaults.selector_btn_pay_customer_cart ).on('click',function(){
|
|
// $.ajax({
|
|
// url: app.defaults.url_pay_customer_card,
|
|
// type: 'post',
|
|
// data: {},
|
|
// success: function (response) {
|
|
// if ( response.code == 'success'){
|
|
// app.defaults.customer_cart = response.customer_cart;
|
|
// refreshCustomerCart();
|
|
// }
|
|
// $.notify(response.message, { 'type' : response.code });
|
|
// },
|
|
// error: function(){
|
|
// alert('Hiba történt');
|
|
// }
|
|
// }
|
|
// );
|
|
// });
|
|
}
|
|
|
|
|
|
function addBehaviourTypeChangedListener(){
|
|
$(app.defaults.selector_type).change(change);
|
|
}
|
|
|
|
function change(event){
|
|
if ( '#'+event.target.id == app.defaults.selector_type ){
|
|
typeChanged();
|
|
}
|
|
}
|
|
|
|
function typeChanged(){
|
|
validateTypeChanged();
|
|
refresh();
|
|
}
|
|
|
|
function validateTypeChanged(){
|
|
validateType();
|
|
validateStartDate();
|
|
validateEndDate();
|
|
validateMaxUsageCount();
|
|
validatePriceBrutto();
|
|
validateAccount();
|
|
}
|
|
|
|
function validateType(){
|
|
var type;
|
|
type = +$(app.defaults.selector_type).val();
|
|
app.defaults.ticket_type = null;
|
|
for ( var i = 0; i < app.defaults.types.length; i++ ){
|
|
if ( app.defaults.types[i].id_ticket_type == type){
|
|
app.defaults.ticket_type = app.defaults.types[i];
|
|
break;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
function validateStartDate(){
|
|
app.defaults.start_date = moment( $( app.defaults.selector_start ).val(), app.defaults.date_format_moment) ;
|
|
|
|
if ( !app.defaults.start_date.isValid() ){
|
|
app.defaults.start_date = moment();
|
|
}
|
|
|
|
}
|
|
|
|
function validateEndDate(){
|
|
var units;
|
|
units = app.defaults.ticket_type.time_unit_count;
|
|
app.defaults.end_date = moment(app.defaults.start_date);
|
|
switch(app.defaults.ticket_type.time_unit_type){
|
|
case app.defaults.time_unit_day:
|
|
app.defaults.end_date.add( units, 'days');
|
|
app.defaults.end_date.subtract( 1, 'days');
|
|
break;
|
|
case app.defaults.time_unit_month:
|
|
app.defaults.end_date.add( units, 'month');
|
|
app.defaults.end_date.subtract( 1, 'days');
|
|
break;
|
|
case app.defaults.time_unit_month_reference:
|
|
if ( units > 1){
|
|
app.defaults.end_date.add( units -1, 'month');
|
|
}
|
|
app.defaults.end_date.endOf('month');
|
|
break;
|
|
}
|
|
}
|
|
|
|
function validateMaxUsageCount(){
|
|
app.defaults.max_usage_count = app.defaults.ticket_type.max_usage_count;
|
|
}
|
|
|
|
function validatePriceBrutto(){
|
|
app.defaults.price = app.defaults.ticket_type.price_brutto;
|
|
}
|
|
function validateAccount(){
|
|
app.defaults.id_account = $('#ticketcreate-id_account').val();
|
|
}
|
|
|
|
function refresh(){
|
|
console.info( app.defaults.start_date.toDate());
|
|
$(app.defaults.selector_start ).val( app.defaults.start_date.format( app.defaults.date_format_moment ) );
|
|
$(app.defaults.selector_end ).val( app.defaults.end_date.format( app.defaults.date_format_moment ) );
|
|
$(app.defaults.selector_account ).val(app.defaults.id_account);
|
|
$(app.defaults.selector_price ).val(app.defaults.price);
|
|
$(app.defaults.selector_max_usage_count ).val(app.defaults.max_usage_count);
|
|
}
|
|
|
|
} |