Last active
July 18, 2016 08:03
-
-
Save minya92/7073622eff5f337b1f75bcda3581bd5f to your computer and use it in GitHub Desktop.
Операции в сессии
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @author Alexey | |
* @module | |
*/ | |
function TradeOperationsInSession(aContainer, aSessionId, aReturn) { | |
console.log(aSessionId); | |
var self = this, model = this.model; | |
if(aReturn) | |
var header = ["Время", "Позиция", "Сумма", "Возврат"]; | |
else | |
var header = ["Время", "Позиция", "Сумма"]; | |
self.container = cmn.createElement("div", "", aContainer); | |
var grid = new wf.Table(self.container, header); | |
var du = new DatesUtils(); | |
if (typeof devices == "undefined") | |
devices = new Devices(); | |
var data, printdata; | |
var tradeModeule = Session.getModule("TradeAdminModule"); | |
if (session.getUserRole() == 'barista') { | |
if (typeof devices == "undefined") | |
devices = new Devices(); | |
function print(){ | |
devices.printers.printXReport(printdata); | |
} | |
var btnPrint = wf.Button('btn btn-primary', self.container, 'Печатать', 'Печать', 'Печатать', print); | |
} | |
self.setSession = function(aSession) { | |
grid.prepare(); | |
model.dsTradeOperationsInSession.params.session_id = aSession; | |
model.dsTradeOperationsInSession.requery(function() { | |
data = []; | |
printdata = []; | |
var prevOperation = null; | |
function pushOperation() { | |
if (prevOperation) { | |
var op = [prevOperation.time, prevOperation.items, prevOperation.sum + " р. " + prevOperation.pay_type]; | |
if(aReturn) | |
op.push(prevOperation.operation_type != 1000?"<span class = 'btn btn-primary return' id='"+prevOperation.id+"' sum='"+prevOperation.sum+"'>Оформить возврат</span>":" "); | |
data.push(op); | |
printdata.push([prevOperation.time]); | |
printdata.push([prevOperation.pay_type, prevOperation.sum + " р."]); | |
} | |
} | |
model.dsTradeOperationsInSession.forEach(function (md) { | |
if (!!prevOperation && md.trade_cash_box_operation_id === prevOperation.id) { | |
prevOperation.items.push({0: md.item_name, 1: md.items_quantity + md.item_measure, customClass: 'cash-sell'}); | |
} else { | |
pushOperation(); | |
prevOperation = {}; | |
prevOperation.id = md.trade_cash_box_operation_id; | |
prevOperation.time = du.timeToShortString(md.operation_date); | |
prevOperation.sum = md.operation_sum; | |
prevOperation.pay_type = md.type_name; | |
prevOperation.pay_type = md.type_name; | |
prevOperation.operation_type = md.operation_type; | |
prevOperation.items = []; | |
if (md.operation_type === 101 || md.operation_type === 105) | |
prevOperation.items.push({0: md.comment_text, customClass: (md.operation_type === 105 ? 'cash-in' : 'cash-out')}); | |
else | |
prevOperation.items.push({0: md.item_name, 1: md.items_quantity + md.item_measure, customClass: 'cash-sell'}); | |
} | |
}); | |
pushOperation(); | |
grid.setData(data); | |
$('.return').click(returnClick); | |
}); | |
}; | |
if (aSessionId) | |
self.setSession(aSessionId); | |
var sum; | |
function returnClick(){ | |
var id = $(this).attr('id'); | |
sum = $(this).attr('sum'); | |
bootbox.prompt({ | |
title: "Введите сумму возврата:", | |
value: sum, | |
callback: function(aSum){ | |
if(aSum){ | |
if(+aSum > +sum){ | |
bootbox.alert("<b>Некорректный ввод!</b><br>Сумма возврата не может превышать сумму операции", function(){}); | |
} else { | |
var res = tradeModeule.cancelOperation(id, session.tradePoint, aSum); | |
if(res){ | |
devices.printers.refund(+res, "Возврат товара"); | |
bootbox.alert("Операция возврата проведена успешно!<br><br>Верните клиенту: <b>" + res + "р.</b>", function(){ | |
(new cmn.Modal).hide(); | |
}); | |
} else { | |
bootbox.alert("<b>Не удалось провести операцию возврата!</b><br>Возможно не хватает денег в кассе, попробуйте пополнить кассу и повторите попытку.", function(){ | |
(new cmn.Modal).hide(); | |
}); | |
} | |
} | |
} | |
} | |
}); | |
} | |
function dsTradeOperationsInSessionOnRequeried(evt) {//GEN-FIRST:event_dsTradeOperationsInSessionOnRequeried | |
}//GEN-LAST:event_dsTradeOperationsInSessionOnRequeried | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment