Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick 2.5
- import ui_components 1.0
- import core_components 1.0
- import QtQuick.Layouts 1.1
- import QtQuick.Controls 2.0
- import QtQuick.Controls 1.4
- NNUIPage {
- statusBarTitle: "Отчёт"
- property bool loading: false
- property var inventarizationData:({inventory_result: {
- wh_excess:[],
- match: [],
- site_excess: []
- }})
- property var scannedCodes: session.stateMachine.context.scannedInventarizationCodes
- property var reportChapterOrder: ['wh_excess', 'match', 'site_excess']
- property var reportTypesInfo: ({
- wh_excess: {
- not_found_text: "Не найдено",
- display_name: 'Есть на складе, но нет в системе',
- color: "#173da6",
- },
- match: {
- not_found_text: "Не найдены",
- display_name: 'Успешно сопоставленные пачки',
- color: "#18a556",
- },
- site_excess:{
- not_found_text: "Не обнаружены",
- display_name: 'Нет на складе, но есть в системе',
- color: "#f06730",
- },
- })
- function chapterByName(name) {
- return chaptersRepeater.itemAt(reportChapterOrder.indexOf(name));
- }
- function getVolume(batchData) {
- return batchData.batch_length
- *batchData.batch_width
- *batchData.batch_thickness
- *batchData.batch_quantity/1000000000.0;
- }
- RowLayout {
- anchors.fill: parent
- Repeater {
- id: chaptersRepeater
- model: reportChapterOrder
- ColumnLayout {
- Layout.fillHeight: true
- property var chapterName: modelData
- property var chapterData: reportTypesInfo[chapterName]
- property double volume: 0.0
- property var batchModel: ListModel{
- onCountChanged: {
- var v = 0.0
- for(var i = 0; i < count; i ++) {
- if(get(i).batch_not_found !== true)
- v += getVolume(get(i));
- }
- volume = v;
- }
- }
- function fillFromData(inputData) {
- asyncFiller.sendMessage({model: batchModel, sourceData: inputData[chapterName]});
- }
- WorkerScript { id: asyncFiller; source: "model_filler.js" }
- NNText {
- anchors.horizontalCenter: parent.horizontalCenter
- text: chapterData.display_name
- font.pixelSize: 22
- height: 50
- verticalAlignment: Text.AlignBottom
- opacity: batchModel.count > 0 ? 1.0: 0.0
- }
- NNText {
- text: chapterData.not_found_text
- anchors.horizontalCenter: parent.horizontalCenter
- font.pixelSize: 19
- visible: batchModel.count == 0 && !loading
- color: "#f94b2a"
- }
- NNText {
- id: textSummaryWHExcess
- anchors.horizontalCenter: parent.horizontalCenter
- font.pixelSize: 19
- visible: batchModel.count > 0
- color: "#e1feaf"
- text: "%1 шт., %2 м³".arg(batchModel.count).arg(volume.toFixed(2))
- }
- BatchListView {
- Layout.fillHeight: true
- anchors.horizontalCenter: parent.horizontalCenter
- model: batchModel
- delegate: BatchBlock{
- blColor: chapterData.color
- val2ui: val2uiTransform
- }
- }
- }
- }
- }
- BusyIndicator {
- id: busyIndicator
- anchors.centerIn: parent
- width: 100
- height: 100
- running: loading
- }
- onScannedCodesChanged: {
- if(scannedCodes != undefined && scannedCodes.length>0) {
- loading = true
- rest.post('inventory',
- {export:scannedCodes},
- function(resp, code) {
- if(code != 200)
- {
- console.log("'inventory request failed'");
- loading = false;
- return;
- }
- var rcvCounter = 0;
- function createHandler(batchIndex) {
- return function(d, code) {
- var dt = getEmptyData();
- if(d.length === 0) {
- dt.batch_not_found = true;
- console.log("Could not find batch: ", code);
- }
- else {
- d[0].not_found = false;
- d[0].deleted = false;
- fillBatchData(dt, d[0]);
- }
- dt['batch_time'] = dt.batch_timestamp.slice(0, -13);
- chapterByName('wh_excess').batchModel.append(dt);
- rcvCounter ++;
- if(rcvCounter == resp.inventory_result.wh_excess.length) {
- loading = false;
- }
- };
- }
- if (resp.inventory_result.wh_excess.length > 0) {
- loading = true;
- for(var i = 0; i < resp.inventory_result.wh_excess.length; i ++) {
- rest.get("plywood_batches?barcode_id="+resp.inventory_result.wh_excess[i].pack_id, createHandler(i), true);
- }
- } else {
- loading = false;
- }
- chapterByName('match').fillFromData(resp.inventory_result);
- chapterByName('site_excess').fillFromData(resp.inventory_result);
- });
- }
- }
- onDisappeared: {
- session.stateMachine.context.scannedInventarizationCodes = [];
- session.stateMachine.contextChanged();
- inventarizationData = {inventory_result: {
- wh_excess:[],
- match: [],
- site_excess: []
- }};
- chaptersRepeater.model = []
- chaptersRepeater.model = reportChapterOrder
- }
- function fillBatchData(bd, serverData) {
- for(var p in serverData) {
- bd['batch_' + p] = serverData[p]
- }
- }
- function getEmptyData() {
- return {
- batch_pack_id: null,
- batch_not_found: null,
- batch_quantity: null,
- batch_shipped: null,
- batch_length: null,
- batch_barcode_confirmed: null,
- batch_width: null,
- batch_deleted: null,
- batch_thickness: null,
- batch_sort_1: null,
- batch_sort_2: null,
- batch_comment: null,
- batch_timestamp: null,
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement